theprogrammablemind_4wp 7.7.0-beta.0 → 7.7.0-beta.10
Sign up to get free protection for your applications and to get access to all the features.
- package/client.js +111 -33
- package/package.json +3 -2
- package/src/config.js +49 -52
- package/src/generators.js +0 -1
- package/src/helpers.js +2 -0
package/client.js
CHANGED
@@ -32,16 +32,26 @@ const pickObjects = (testConfig, objects) => {
|
|
32
32
|
|
33
33
|
const getAsk = (config) => (uuid) => (asks) => {
|
34
34
|
for (let ask of asks) {
|
35
|
+
let oneShot = true // default
|
36
|
+
if (ask.oneShot === false) {
|
37
|
+
oneShot = false
|
38
|
+
}
|
35
39
|
config.addSemantic({
|
36
40
|
uuid,
|
37
|
-
oneShot
|
41
|
+
oneShot,
|
38
42
|
match: (args) => ask.matchr(args),
|
39
43
|
apply: (args) => ask.applyr(args)
|
40
44
|
})
|
41
45
|
}
|
46
|
+
let oneShot = true
|
47
|
+
for (let ask of asks) {
|
48
|
+
if (ask.oneShot === false) {
|
49
|
+
oneShot = false
|
50
|
+
}
|
51
|
+
}
|
42
52
|
config.addSemantic({
|
43
53
|
uuid,
|
44
|
-
oneShot
|
54
|
+
oneShot,
|
45
55
|
match: ({context}) => context.marker == 'controlEnd' || context.marker == 'controlBetween',
|
46
56
|
apply: (args) => {
|
47
57
|
for (let ask of asks) {
|
@@ -64,7 +74,7 @@ const getAsk = (config) => (uuid) => (asks) => {
|
|
64
74
|
break
|
65
75
|
}
|
66
76
|
}
|
67
|
-
|
77
|
+
}
|
68
78
|
})
|
69
79
|
}
|
70
80
|
|
@@ -169,6 +179,7 @@ const setupArgs = (args, config, logs, hierarchy) => {
|
|
169
179
|
apis: getAPIs(uuid)
|
170
180
|
}
|
171
181
|
}
|
182
|
+
Object.assign(args, args.getUUIDScoped(this.uuid))
|
172
183
|
args.breakOnSemantics = false
|
173
184
|
args.theDebugger = {
|
174
185
|
breakOnSemantics: (value) => args.breakOnSemantics = value
|
@@ -179,11 +190,23 @@ const setupArgs = (args, config, logs, hierarchy) => {
|
|
179
190
|
args.log = (message) => logs.push(message)
|
180
191
|
|
181
192
|
args.addAssumedScoped = (args, assumed) => {
|
193
|
+
const addAssumed = (args, ...moreAssumed) => {
|
194
|
+
return { ...args, assumed: Object.assign({}, (args.assumed || {}), ...moreAssumed) }
|
195
|
+
}
|
196
|
+
|
182
197
|
args.s = (c) => config.getSemantics(logs).apply(args, c)
|
183
|
-
args.g = (c) =>
|
184
|
-
|
185
|
-
|
186
|
-
args.
|
198
|
+
args.g = (c, a = {}) => {
|
199
|
+
return config.getGenerators(logs).apply(addAssumed(args, a), c, a)
|
200
|
+
}
|
201
|
+
args.gp = (c, a = {}) => {
|
202
|
+
return config.getGenerators(logs).apply(addAssumed(args, a, {paraphrase: true, isResponse: false, response: false}), c, {paraphrase: true, isResponse: false, response: false})
|
203
|
+
}
|
204
|
+
args.gr = (c, a = {}) => {
|
205
|
+
return config.getGenerators(logs).apply(addAssumed(args, a, {paraphrase: false, isResponse: true}), { ...c, paraphrase: false, isResponse: true })
|
206
|
+
}
|
207
|
+
args.e = (c) => {
|
208
|
+
return config.getEvaluator(args.s, args.calls, logs, c)
|
209
|
+
}
|
187
210
|
args.gs = gs(args.g)
|
188
211
|
args.gsp = gs(args.gp)
|
189
212
|
args.gsr = gs(args.gr)
|
@@ -467,8 +490,6 @@ const processContextsB = ({ config, hierarchy, semantics, generators, json, isTe
|
|
467
490
|
}
|
468
491
|
// assumed = { paraphrase: true, response: false };
|
469
492
|
assumed = { paraphrase: true, isResponse: false, response: false };
|
470
|
-
// args.g = (c) => config.getGenerators(json.logs).apply({...args, assumed}, c, assumed)
|
471
|
-
// args.gs = gs(args.g)
|
472
493
|
if (generateParenthesized) {
|
473
494
|
config.parenthesized = false
|
474
495
|
}
|
@@ -479,8 +500,6 @@ const processContextsB = ({ config, hierarchy, semantics, generators, json, isTe
|
|
479
500
|
paraphrasesParenthesized = config.getGenerators(json.logs).apply({...args, assumed}, contextPrime, assumed)
|
480
501
|
config.parenthesized = false
|
481
502
|
}
|
482
|
-
// args.g = (c) => config.getGenerators(json.logs).apply(args, c)
|
483
|
-
// args.gs = gs(args.g)
|
484
503
|
contextsPrime.push(contextPrime)
|
485
504
|
generatedPrime.push(generated)
|
486
505
|
paraphrasesPrime.push(paraphrases)
|
@@ -613,11 +632,25 @@ const loadInstance = (config, instance) => {
|
|
613
632
|
// config.addInternal(results, useOldVersion = true, skipObjects = false, includeNamespaces = true, allowNameToBeNull = false)
|
614
633
|
// config.addInternal(config.template.queries[i], { handleCalculatedProps: true } )
|
615
634
|
config.addInternal(instance.template.queries[i], { addFirst: true, handleCalculatedProps: true } )
|
635
|
+
} else if (results.apply) {
|
636
|
+
const objects = config.get('objects')
|
637
|
+
const args = { objects, getObjects: getObjects(objects) }
|
638
|
+
if (instance.queries) {
|
639
|
+
args.isInstance = `instance${i}`
|
640
|
+
args.instance = instance.queries[i]
|
641
|
+
}
|
642
|
+
setupArgs(args, config, config.logs, hierarchy)
|
643
|
+
results.apply(args)
|
616
644
|
} else {
|
617
645
|
if (results.skipSemantics) {
|
618
646
|
config.config.skipSemantics = results.skipSemantics
|
619
647
|
}
|
620
|
-
|
648
|
+
const args = { config, hierarchy, json: results, commandLineArgs: {} }
|
649
|
+
if (instance.queries) {
|
650
|
+
args.isInstance = `instance${i}`
|
651
|
+
args.instance = instance.queries[i]
|
652
|
+
}
|
653
|
+
processContextsB(args)
|
621
654
|
if (results.skipSemantics) {
|
622
655
|
config.config.skipSemantics = null
|
623
656
|
}
|
@@ -1182,9 +1215,9 @@ const defaultInnerProcess = (config, errorHandler, responses) => {
|
|
1182
1215
|
}
|
1183
1216
|
|
1184
1217
|
if (responses.explain_priorities) {
|
1185
|
-
console.log("Explain Priorities
|
1186
|
-
for ([
|
1187
|
-
console.log(` ${JSON.stringify(
|
1218
|
+
console.log("Explain Priorities")
|
1219
|
+
for ([inputs, output, reason] of responses.explain_priorities) {
|
1220
|
+
console.log(` inputs: ${JSON.stringify(inputs)} output: ${JSON.stringify(output)} reason: ${reason}`)
|
1188
1221
|
}
|
1189
1222
|
}
|
1190
1223
|
const objects = config.get('objects').namespaced[config.uuid]
|
@@ -1241,7 +1274,7 @@ const defaultProcess = ({ config, errorHandler }) => async (promise) => {
|
|
1241
1274
|
}
|
1242
1275
|
|
1243
1276
|
// builtTemplate saveInstance
|
1244
|
-
const rebuildTemplate = async ({ config, target, template, errorHandler = defaultErrorHandler }) => {
|
1277
|
+
const rebuildTemplate = async ({ config, target, previousResultss, startOfChanges, template, errorHandler = defaultErrorHandler }) => {
|
1245
1278
|
const accumulators = {
|
1246
1279
|
resultss: [],
|
1247
1280
|
fragments: [],
|
@@ -1254,7 +1287,7 @@ const rebuildTemplate = async ({ config, target, template, errorHandler = defaul
|
|
1254
1287
|
finish()
|
1255
1288
|
return
|
1256
1289
|
}
|
1257
|
-
const { property, hierarchy, query: queryOrExtraConfig, initializer, skipSemantics } = queries.shift()
|
1290
|
+
const { property, hierarchy, query: queryOrExtraConfig, previousResults, initializer, skipSemantics } = queries.shift()
|
1258
1291
|
// queries are strings or { query: "blah", development: true/false }
|
1259
1292
|
if (typeof queryOrExtraConfig === 'string' || queryOrExtraConfig.query) {
|
1260
1293
|
let query = queryOrExtraConfig;
|
@@ -1276,7 +1309,15 @@ const rebuildTemplate = async ({ config, target, template, errorHandler = defaul
|
|
1276
1309
|
}
|
1277
1310
|
}
|
1278
1311
|
try {
|
1279
|
-
|
1312
|
+
let results
|
1313
|
+
let prMessage = ''
|
1314
|
+
if (previousResults && previousResults.query == query.query) {
|
1315
|
+
results = previousResults
|
1316
|
+
prMessage = ' Using previous results. use -rtf for a hard rebuild of everything on the server side.'
|
1317
|
+
loadInstance(config, { resultss: [results] })
|
1318
|
+
} else {
|
1319
|
+
results = await _process(config, query.query, {initializer, rebuildingTemplate: true})
|
1320
|
+
}
|
1280
1321
|
if (config.config.debug) {
|
1281
1322
|
// TODO pass in the error handler like the other ones
|
1282
1323
|
defaultInnerProcess(config, defaultErrorHandler, results)
|
@@ -1285,9 +1326,9 @@ const rebuildTemplate = async ({ config, target, template, errorHandler = defaul
|
|
1285
1326
|
console.log(`query "${query.query}". There is ${results.contexts.length} contexts in the results. Make sure its producing the results that you expect.`)
|
1286
1327
|
throw new Error(`query "${query.query}". There is ${results.contexts.length} contexts in the results. Make sure its producing the results that you expect.`)
|
1287
1328
|
} else if (results.paraphrases[0] != query.query) {
|
1288
|
-
console.log(`query "${query.query}". The paraphrase is different from the query "${results.paraphrases[0]}"
|
1329
|
+
console.log(`query "${query.query}". The paraphrase is different from the query "${results.paraphrases[0]}".${prMessage}`)
|
1289
1330
|
} else {
|
1290
|
-
console.log(`query ${query.query}`)
|
1331
|
+
console.log(`query "${query.query}".${prMessage}`)
|
1291
1332
|
}
|
1292
1333
|
global.transitoryMode = transitoryMode
|
1293
1334
|
config.config.skipSemantics = null
|
@@ -1304,6 +1345,15 @@ const rebuildTemplate = async ({ config, target, template, errorHandler = defaul
|
|
1304
1345
|
config.config.skipSemantics = null
|
1305
1346
|
errorHandler(error)
|
1306
1347
|
}
|
1348
|
+
} else if (typeof queryOrExtraConfig == 'function') {
|
1349
|
+
console.log('calling initialize function')
|
1350
|
+
const initFunction = queryOrExtraConfig
|
1351
|
+
const objects = config.get('objects')
|
1352
|
+
const args = { objects, getObjects: getObjects(objects) }
|
1353
|
+
setupArgs(args, config, config.logs, hierarchy)
|
1354
|
+
initFunction(args)
|
1355
|
+
accumulators[property].push({ apply: queryOrExtraConfig })
|
1356
|
+
await looper(queries)
|
1307
1357
|
} else {
|
1308
1358
|
// extra config is def from a time like operators or bridges or words etc
|
1309
1359
|
// it will just get added to the config
|
@@ -1336,8 +1386,11 @@ const rebuildTemplate = async ({ config, target, template, errorHandler = defaul
|
|
1336
1386
|
const stabilizeOutput = (template) => {
|
1337
1387
|
stabilizeAssociations(template.associations)
|
1338
1388
|
const stabilize = (results) => {
|
1339
|
-
for (let
|
1340
|
-
|
1389
|
+
for (let i = 0; i < results.length; ++i) {
|
1390
|
+
const result = results[i]
|
1391
|
+
if (result.apply) {
|
1392
|
+
result.apply = result.apply.toString()
|
1393
|
+
} else if (result.extraConfig) {
|
1341
1394
|
} else {
|
1342
1395
|
delete result.load_cache_time
|
1343
1396
|
delete result.times
|
@@ -1375,7 +1428,13 @@ const rebuildTemplate = async ({ config, target, template, errorHandler = defaul
|
|
1375
1428
|
}
|
1376
1429
|
let todo = []
|
1377
1430
|
todo = todo.concat((template.initializers || []).map((query) => { return { initializer: true, property: 'resultss', query, skipSemantics: false || query.skipSemantics } }))
|
1378
|
-
todo = todo.concat((template.queries || []).map((query) => {
|
1431
|
+
todo = todo.concat((template.queries || []).map((query, index) => {
|
1432
|
+
let pr
|
1433
|
+
if (index < startOfChanges) {
|
1434
|
+
pr = previousResultss[index]
|
1435
|
+
}
|
1436
|
+
return { property: 'resultss', query, previousResults: pr, skipSemantics: false || query.skipSemantics}
|
1437
|
+
}))
|
1379
1438
|
todo = todo.concat((template.fragments || []).map((query) => { return Object.assign({}, toProperties(query), { property: 'fragments', skipSemantics: false }) }))
|
1380
1439
|
todo = todo.concat((template.semantics || []).map((definition) => { return { property: 'semantics', query: `${definition.from}\n${definition.to}`, skipSemantics: true } }))
|
1381
1440
|
await looper(Object.assign([], todo))
|
@@ -1490,13 +1549,14 @@ const knowledgeModuleImpl = async ({
|
|
1490
1549
|
parser.add_argument('-tnp', '--testNoParenthesized', { action: 'store_true', help: 'Don\' check parenthesized differences for the tests' })
|
1491
1550
|
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' })
|
1492
1551
|
// 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.' })
|
1493
|
-
parser.add_argument('-rt', '--rebuildTemplate', { action: 'store_true', help: 'Force a template rebuild' })
|
1552
|
+
parser.add_argument('-rt', '--rebuildTemplate', { action: 'store_true', help: 'Force a template rebuild. Using optimization where if the query/config has not changed it will use the previous value. One there is a change all subsequence query/configs will be run.' })
|
1553
|
+
parser.add_argument('-rtf', '--rebuildTemplateFull', { action: 'store_true', help: 'Force a template rebuild. Skip the optimization' })
|
1494
1554
|
parser.add_argument('-l', '--loop', { action: 'store_true', help: 'Run a loop so that multiply queries may be run' })
|
1495
1555
|
parser.add_argument('-i', '--info', { action: 'store_true', help: 'Print meta-data for the module' })
|
1496
1556
|
parser.add_argument('-v', '--vimdiff', { action: 'store_true', help: 'For failures run vimdiff' })
|
1497
1557
|
parser.add_argument('-g', '--greg', { action: 'store_true', help: 'Set the server to be localhost so I can debug stuff' })
|
1498
1558
|
parser.add_argument('-cl', '--checkForLoop', { nargs: "?", help: 'Check for loops in the priorities, Optional argument is list of operator keys to consider. For example [["banana", 0], ["food", 1]]' })
|
1499
|
-
parser.add_argument('-r', '--
|
1559
|
+
parser.add_argument('-r', '--reset', { action: 'store_true', help: 'Get the server to bypass the cache and rebuild everything' })
|
1500
1560
|
parser.add_argument('-q', '--query', { help: 'Run the specified query' })
|
1501
1561
|
parser.add_argument('-ip ', '--server', { help: 'Server to run against' })
|
1502
1562
|
parser.add_argument('-qp ', '--queryParams', { help: 'Query params for the server call' })
|
@@ -1521,6 +1581,10 @@ const knowledgeModuleImpl = async ({
|
|
1521
1581
|
const args = parser.parse_args()
|
1522
1582
|
args.count = args.count || 1
|
1523
1583
|
|
1584
|
+
if (args.rebuildTemplateFull) {
|
1585
|
+
args.rebuildTemplate = true
|
1586
|
+
}
|
1587
|
+
|
1524
1588
|
if (args.parenthesized) {
|
1525
1589
|
config.parenthesized = true
|
1526
1590
|
}
|
@@ -1611,6 +1675,10 @@ const knowledgeModuleImpl = async ({
|
|
1611
1675
|
config.config.debug = true
|
1612
1676
|
}
|
1613
1677
|
|
1678
|
+
if (args.reset) {
|
1679
|
+
config.config.skip_cache = true
|
1680
|
+
}
|
1681
|
+
|
1614
1682
|
if (args.explainPriorities) {
|
1615
1683
|
config.config.explain_priorities = true
|
1616
1684
|
}
|
@@ -1711,23 +1779,33 @@ const knowledgeModuleImpl = async ({
|
|
1711
1779
|
checkTemplate(template)
|
1712
1780
|
|
1713
1781
|
if (template) {
|
1714
|
-
|
1715
|
-
if (
|
1782
|
+
let needsRebuild
|
1783
|
+
if (args.rebuildTemplate && !args.rebuildTemplateFull) {
|
1784
|
+
// get the startOfChanges for the partial rebuild
|
1785
|
+
needsRebuild = config.needsRebuild(template.template, template.instance, { ...options, rebuild: false })
|
1786
|
+
} else {
|
1787
|
+
// do a check or full rebuild
|
1788
|
+
needsRebuild = config.needsRebuild(template.template, template.instance, options)
|
1789
|
+
}
|
1790
|
+
|
1791
|
+
if (needsRebuild.needsRebuild) {
|
1792
|
+
if (needsRebuild.previousResultss) {
|
1793
|
+
console.log("Rebuild using the optimization to use previous results until a change is hit. For a full rebuild use -rtf")
|
1794
|
+
}
|
1716
1795
|
console.log(`This module "${config.name}" needs rebuilding all other arguments will be ignored. Try again after the template is rebuilt.`)
|
1717
1796
|
options.rebuild = true
|
1718
1797
|
config.config.rebuild = true
|
1719
1798
|
}
|
1720
1799
|
try {
|
1721
|
-
config.load(template.template, template.instance, { rebuild: needsRebuild })
|
1800
|
+
config.load(template.template, template.instance, { rebuild: needsRebuild.needsRebuild || options.rebuild, previousResultss: needsRebuild.previousResultss, startOfChanges: needsRebuild.startOfChanges })
|
1722
1801
|
} catch( e ) {
|
1723
|
-
|
1724
|
-
console.error(`Error loading template for ${config.name}. ${e.error ? e.error : e}`)
|
1802
|
+
console.error(`Error loading template for ${config.name}. ${e.error ? e.error : e}${e.stack ? e.stack : ''}`)
|
1725
1803
|
runtime.process.exit(-1)
|
1726
1804
|
}
|
1727
1805
|
if (!args.query) {
|
1728
1806
|
printConfig()
|
1729
1807
|
}
|
1730
|
-
if (needsRebuild) {
|
1808
|
+
if (needsRebuild.needsRebuild) {
|
1731
1809
|
return
|
1732
1810
|
}
|
1733
1811
|
}
|
@@ -1890,7 +1968,7 @@ const knowledgeModuleImpl = async ({
|
|
1890
1968
|
if (!(useTestConfig.check && useTestConfig.check.length > 0)) {
|
1891
1969
|
console.log('use -v arg to write files expected.json and actual.json in the current directory for detailed comparison. Or do -s and then git diff the changes.')
|
1892
1970
|
// console.log(JSON.stringify(contexts))
|
1893
|
-
console.log('**************************** ERRORS ************************')
|
1971
|
+
console.log('**************************** THERE WERE ERRORS ************************')
|
1894
1972
|
}
|
1895
1973
|
}
|
1896
1974
|
}
|
@@ -1976,7 +2054,7 @@ const knowledgeModuleImpl = async ({
|
|
1976
2054
|
}
|
1977
2055
|
|
1978
2056
|
if (template) {
|
1979
|
-
if (config.needsRebuild(template.template, template.instance, { isModule: !isProcess })) {
|
2057
|
+
if (config.needsRebuild(template.template, template.instance, { isModule: !isProcess }).needsRebuild) {
|
1980
2058
|
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.`
|
1981
2059
|
throw new Error(error)
|
1982
2060
|
}
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"devDependencies": {
|
3
3
|
"eslint-plugin-import": "^2.23.4",
|
4
|
-
"jest": "^
|
4
|
+
"jest": "^29.7.0",
|
5
5
|
"@typescript-eslint/parser": "^4.28.4",
|
6
6
|
"@typescript-eslint/eslint-plugin": "^4.28.4",
|
7
7
|
"eslint-plugin-node": "^11.1.0",
|
@@ -12,6 +12,7 @@
|
|
12
12
|
"scripts": {
|
13
13
|
"to:debug": "node inspect node_modules/.bin/jest --runInBand -t NEO23",
|
14
14
|
"test:debug": "node inspect node_modules/.bin/jest --runInBand --config ./jest.config.json",
|
15
|
+
"td": "node inspect node_modules/.bin/jest --runInBand --config ./jest.config.json",
|
15
16
|
"tod": "node inspect node_modules/.bin/jest --runInBand -t NEO23",
|
16
17
|
"lint:fix": "eslint \"**/*.js\" --fix",
|
17
18
|
"lint": "eslint \"**/*.js\"",
|
@@ -64,6 +65,6 @@
|
|
64
65
|
"json-stable-stringify": "^1.0.1",
|
65
66
|
"node-fetch": "^2.6.1"
|
66
67
|
},
|
67
|
-
"version": "7.7.0-beta.
|
68
|
+
"version": "7.7.0-beta.10",
|
68
69
|
"license": "ISC"
|
69
70
|
}
|
package/src/config.js
CHANGED
@@ -965,7 +965,7 @@ class Config {
|
|
965
965
|
}
|
966
966
|
|
967
967
|
// { rebuild: false, isModule: false }
|
968
|
-
needsRebuild(template, instance, options) {
|
968
|
+
needsRebuild (template, instance, options) {
|
969
969
|
if (options.rebuild) {
|
970
970
|
return true
|
971
971
|
}
|
@@ -983,6 +983,8 @@ class Config {
|
|
983
983
|
if (typeof queryOrConfig == 'string') {
|
984
984
|
const query = queryOrConfig
|
985
985
|
return query
|
986
|
+
} else if (typeof queryOrConfig == 'function') {
|
987
|
+
return { apply: queryOrConfig.toString() }
|
986
988
|
} else {
|
987
989
|
const config = { ...queryOrConfig }
|
988
990
|
delete config.where
|
@@ -1058,7 +1060,22 @@ class Config {
|
|
1058
1060
|
return elements.map( toCanonicalQuery )
|
1059
1061
|
}
|
1060
1062
|
|
1061
|
-
const
|
1063
|
+
const templateQueries = toCanonicalQueries(template.queries || []).map(helpers.updateQueries)
|
1064
|
+
const instanceQueries = toCanonicalQueries(instance.queries || [])
|
1065
|
+
let sameQueries = true
|
1066
|
+
let startOfChanges;
|
1067
|
+
for (let iq = 0; iq < templateQueries.length; ++iq) {
|
1068
|
+
if (!helpers.safeEquals(templateQueries[iq], instanceQueries[iq])) {
|
1069
|
+
sameQueries = false
|
1070
|
+
startOfChanges = iq
|
1071
|
+
}
|
1072
|
+
}
|
1073
|
+
|
1074
|
+
// things were deleted case
|
1075
|
+
if (templateQueries.length < instanceQueries.length) {
|
1076
|
+
startOfChanges = instanceQueries.length
|
1077
|
+
}
|
1078
|
+
// const sameQueries = helpers.safeEquals(toCanonicalQueries(template.queries || []).map(helpers.updateQueries), toCanonicalQueries(instance.queries || []))
|
1062
1079
|
|
1063
1080
|
const debug = false
|
1064
1081
|
if (debug) {
|
@@ -1067,16 +1084,20 @@ class Config {
|
|
1067
1084
|
debugger
|
1068
1085
|
debugger
|
1069
1086
|
}
|
1070
|
-
console.log("instance", instance)
|
1087
|
+
// console.log("instance", instance)
|
1071
1088
|
console.log("sameQueries", sameQueries)
|
1072
1089
|
console.log("sameFragments", sameFragments)
|
1073
|
-
console.log("templateFragments", templateFragments)
|
1074
|
-
console.log("instanceFragments", instanceFragments)
|
1075
|
-
console.log('template.queries', JSON.stringify(toCanonicalQueries(template.queries || []).map(helpers.updateQueries), null, 2))
|
1076
|
-
console.log("instance.queries", JSON.stringify(toCanonicalQueries(instance.queries || []), null, 2))
|
1090
|
+
// console.log("templateFragments", templateFragments)
|
1091
|
+
// console.log("instanceFragments", instanceFragments)
|
1092
|
+
// console.log('template.queries', JSON.stringify(toCanonicalQueries(template.queries || []).map(helpers.updateQueries), null, 2))
|
1093
|
+
// console.log("instance.queries", JSON.stringify(toCanonicalQueries(instance.queries || []), null, 2))
|
1077
1094
|
}
|
1078
1095
|
}
|
1079
|
-
|
1096
|
+
if (startOfChanges || instance.resultss) {
|
1097
|
+
return { needsRebuild: !(instance && sameQueries && sameFragments), startOfChanges, previousResultss: instance.resultss }
|
1098
|
+
} else {
|
1099
|
+
return { needsRebuild: !(instance && sameQueries && sameFragments) }
|
1100
|
+
}
|
1080
1101
|
}
|
1081
1102
|
|
1082
1103
|
validifyTemplate (template) {
|
@@ -1097,7 +1118,7 @@ class Config {
|
|
1097
1118
|
}
|
1098
1119
|
|
1099
1120
|
// loadTemplate
|
1100
|
-
load (template, instance, options = { rebuild: false } ) {
|
1121
|
+
load (template, instance, options = { rebuild: false, previousResultss: undefined, startOfChanges: undefined } ) {
|
1101
1122
|
this.validifyTemplate(template)
|
1102
1123
|
instance.template = template
|
1103
1124
|
this.logs.push(`loading template for ${this.name}`)
|
@@ -1105,7 +1126,7 @@ class Config {
|
|
1105
1126
|
// TODO fix beforeQuery
|
1106
1127
|
template = { fragments: [], queries: [], ...template }
|
1107
1128
|
template.fragments = template.fragments.concat(this.dynamicFragments)
|
1108
|
-
client.rebuildTemplate({ config: this, target: this.name, beforeQuery: () => {}, template, ...options })
|
1129
|
+
client.rebuildTemplate({ config: this, target: this.name, previousResultss: options.previousResultss, startOfChanges: options.startOfChanges, beforeQuery: () => {}, template, ...options })
|
1109
1130
|
} else {
|
1110
1131
|
// no change
|
1111
1132
|
// this.initInstances.push({ ...instance, name: config.name })
|
@@ -1120,6 +1141,13 @@ class Config {
|
|
1120
1141
|
return !properties.find( (property) => instance[property] && instance[property].length > 0 )
|
1121
1142
|
}
|
1122
1143
|
if (!isEmpty(instance)) {
|
1144
|
+
// fix up apply functions
|
1145
|
+
for (let i = 0; i < instance.resultss.length; ++i) {
|
1146
|
+
const result = instance.resultss[i]
|
1147
|
+
if (result.apply) {
|
1148
|
+
result.apply = template.queries[i]
|
1149
|
+
}
|
1150
|
+
}
|
1123
1151
|
instance.name = this.name
|
1124
1152
|
this.initInstances.push(instance)
|
1125
1153
|
this.instances.push(instance)
|
@@ -2219,8 +2247,6 @@ class Config {
|
|
2219
2247
|
const addInternals = []
|
2220
2248
|
const inits = []
|
2221
2249
|
const initAfterApis = []
|
2222
|
-
const reverseIt = true
|
2223
|
-
const interleaved = true
|
2224
2250
|
this.configs.forEach((km) => {
|
2225
2251
|
const namespace = km.namespace
|
2226
2252
|
this.config.objects.namespaced[km._uuid] = {}
|
@@ -2286,58 +2312,30 @@ class Config {
|
|
2286
2312
|
inits.unshift( () => config._api.initialize({ config: this, km: kmFn, ...args, api: config._api }) )
|
2287
2313
|
// config._api.initialize({ config, api: config._api })
|
2288
2314
|
} else {
|
2289
|
-
|
2290
|
-
inits.unshift(null)
|
2291
|
-
}
|
2315
|
+
inits.unshift(null)
|
2292
2316
|
}
|
2293
2317
|
// config._api.objects = namespacedObjects
|
2294
2318
|
// config._api.config = () => this
|
2295
2319
|
// config._api.uuid = config._uuid
|
2296
2320
|
} else {
|
2297
|
-
|
2298
|
-
inits.unshift(null)
|
2299
|
-
}
|
2321
|
+
inits.unshift(null)
|
2300
2322
|
}
|
2301
2323
|
config.setUUIDs()
|
2302
2324
|
config.applyNamespace(config.config, namespace, config.uuid)
|
2303
2325
|
if (!isSelf) {
|
2304
|
-
|
2305
|
-
addInternals.push(config)
|
2306
|
-
} else {
|
2307
|
-
addInternals.unshift(config)
|
2308
|
-
}
|
2326
|
+
addInternals.unshift(config)
|
2309
2327
|
} else {
|
2310
|
-
|
2311
|
-
addInternals.unshift(null)
|
2312
|
-
}
|
2328
|
+
addInternals.unshift(null)
|
2313
2329
|
}
|
2314
2330
|
km.valid()
|
2315
2331
|
})
|
2316
2332
|
|
2317
2333
|
const generators = this.config.generators
|
2318
2334
|
const semantics = this.config.semantics
|
2319
|
-
|
2320
|
-
|
2321
|
-
this.config.semantics = []
|
2322
|
-
}
|
2335
|
+
this.config.generators = []
|
2336
|
+
this.config.semantics = []
|
2323
2337
|
|
2324
|
-
|
2325
|
-
for (const config of addInternals) {
|
2326
|
-
if (!reverseIt) {
|
2327
|
-
this.addInternal(config, { includeNamespace: false, allowNameToBeNull: true })
|
2328
|
-
} else {
|
2329
|
-
this.addInternalR(config, true, false, false, true)
|
2330
|
-
}
|
2331
|
-
}
|
2332
|
-
// console.log('inits from config', inits)
|
2333
|
-
for (const init of inits) {
|
2334
|
-
init()
|
2335
|
-
}
|
2336
|
-
for (let init of initAfterApis) {
|
2337
|
-
init.config.initializerFn({ ...init.args, kms: this.getConfigs(), isAfterApi: true })
|
2338
|
-
}
|
2339
|
-
this.instances.forEach((instance) => client.loadInstance(this, instance))
|
2340
|
-
} else {
|
2338
|
+
{
|
2341
2339
|
const base = {
|
2342
2340
|
operators: this.config.operators,
|
2343
2341
|
bridges: this.config.bridges,
|
@@ -2353,13 +2351,16 @@ class Config {
|
|
2353
2351
|
this.config.priorities = []
|
2354
2352
|
this.config.associations = { positive: [], negative: [] }
|
2355
2353
|
this.config.words = {}
|
2356
|
-
|
2354
|
+
|
2357
2355
|
for (let i = 0; i < addInternals.length; ++i) {
|
2358
2356
|
let name;
|
2359
2357
|
if (addInternals[i]) {
|
2360
2358
|
this.addInternalR(addInternals[i], true, false, false, true)
|
2361
2359
|
name = addInternals[i].name
|
2362
2360
|
} else{
|
2361
|
+
// the ones defined in config must come after the ones in the templates
|
2362
|
+
this.config.generators = generators.concat(this.config.generators)
|
2363
|
+
this.config.semantics = semantics.concat(this.config.semantics)
|
2363
2364
|
this.addInternalR(base, true, false, false, true)
|
2364
2365
|
name = this.name
|
2365
2366
|
}
|
@@ -2380,10 +2381,6 @@ class Config {
|
|
2380
2381
|
}
|
2381
2382
|
}
|
2382
2383
|
|
2383
|
-
if (reverseIt) {
|
2384
|
-
this.config.generators = generators.concat(this.config.generators)
|
2385
|
-
this.config.semantics = semantics.concat(this.config.semantics)
|
2386
|
-
}
|
2387
2384
|
this.hierarchy.edges = this.config.hierarchy
|
2388
2385
|
this.valid()
|
2389
2386
|
this.checkBridges()
|
package/src/generators.js
CHANGED
package/src/helpers.js
CHANGED
@@ -272,6 +272,8 @@ const mapInPlace = (list, fn) => {
|
|
272
272
|
const updateQueries = (queryOrConfig) => {
|
273
273
|
if (typeof queryOrConfig == 'string' || queryOrConfig.query) {
|
274
274
|
return queryOrConfig
|
275
|
+
} else if (typeof queryOrConfig == 'function') {
|
276
|
+
return { apply: queryOrConfig.toString() }
|
275
277
|
} else {
|
276
278
|
const config = queryOrConfig
|
277
279
|
return functionsToStrings(config)
|