theprogrammablemind_4wp 7.6.0-beta.1 → 7.6.0-beta.10
Sign up to get free protection for your applications and to get access to all the features.
- package/client.js +86 -41
- package/package.json +1 -1
- package/runtime.js +1 -0
- package/src/flatten.js +3 -0
- package/src/generators.js +112 -122
- package/src/project.js +0 -1
package/client.js
CHANGED
@@ -173,22 +173,32 @@ const setupArgs = (args, config, logs, hierarchy) => {
|
|
173
173
|
args.theDebugger = {
|
174
174
|
breakOnSemantics: (value) => args.breakOnSemantics = value
|
175
175
|
}
|
176
|
-
args.s = (c) => config.getSemantics(logs).apply(args, c)
|
177
|
-
args.g = (c) => config.getGenerators(logs).apply(args, c)
|
178
|
-
args.gp = (c) => config.getGenerators(logs).apply(args, { ...c, paraphrase: true, isResponse: false, response: false})
|
179
|
-
args.gr = (c) => config.getGenerators(logs).apply(args, { ...c, paraphrase: false, isResponse: true })
|
180
176
|
if (!logs) {
|
181
177
|
debugger
|
182
178
|
}
|
183
|
-
args.e = (c) => config.getEvaluator(args.s, args.calls, logs, c)
|
184
179
|
args.log = (message) => logs.push(message)
|
185
|
-
|
186
|
-
args.
|
187
|
-
|
180
|
+
|
181
|
+
args.addAssumedScoped = (args, assumed) => {
|
182
|
+
args.s = (c) => config.getSemantics(logs).apply(args, c)
|
183
|
+
args.g = (c) => config.getGenerators(logs).apply(args, c)
|
184
|
+
args.gp = (c) => config.getGenerators(logs).apply({...args, assumed: {paraphrase: true, isResponse: false, response: false}}, c, {paraphrase: true, isResponse: false, response: false})
|
185
|
+
args.gr = (c) => config.getGenerators(logs).apply({...args, assumed: {paraphrase: false, isResponse: true}}, { ...c, paraphrase: false, isResponse: true })
|
186
|
+
args.e = (c) => config.getEvaluator(args.s, args.calls, logs, c)
|
187
|
+
args.gs = gs(args.g)
|
188
|
+
args.gsp = gs(args.gp)
|
189
|
+
args.gsr = gs(args.gr)
|
190
|
+
}
|
191
|
+
// for semantics
|
192
|
+
args.addAssumedScoped(args, {})
|
188
193
|
config.getAddedArgs(args)
|
189
194
|
}
|
190
195
|
|
191
196
|
const gs = (g) => (contexts, separator, lastSeparator) => {
|
197
|
+
if (!Array.isArray(contexts)) {
|
198
|
+
debugger
|
199
|
+
throw new Error("Expected a list")
|
200
|
+
}
|
201
|
+
|
192
202
|
let s = ''
|
193
203
|
if (!separator) {
|
194
204
|
separator = ' '
|
@@ -276,8 +286,9 @@ const processContext = (context, { objects = {}, config, logs = [] }) => {
|
|
276
286
|
setupArgs(args, config, logs, hierarchy)
|
277
287
|
|
278
288
|
context = semantics.apply(args, context)
|
279
|
-
const generated = generators.apply(args, context)
|
280
|
-
const
|
289
|
+
const generated = generators.apply(args, context)
|
290
|
+
const assumed = { paraphrase: true, response: false, isResponse: false }
|
291
|
+
const paraphrases = generators.apply({...args, assumed}, context, { paraphrase: true, response: false, isResponse: false })
|
281
292
|
let responses = []
|
282
293
|
if (context.isResponse) {
|
283
294
|
responses = generated
|
@@ -447,37 +458,29 @@ const processContextsB = ({ config, hierarchy, semantics, generators, json, isTe
|
|
447
458
|
continue
|
448
459
|
}
|
449
460
|
let assumed = { isResponse: true };
|
450
|
-
const generated = contextPrime.isResponse ? config.getGenerators(json.logs).apply(args, contextPrime, assumed)
|
461
|
+
const generated = contextPrime.isResponse ? config.getGenerators(json.logs).apply({...args, assumed}, contextPrime, assumed) : ''
|
451
462
|
let generatedParenthesized = []
|
452
463
|
if (generateParenthesized) {
|
453
464
|
config.parenthesized = true
|
454
|
-
generatedParenthesized = contextPrime.isResponse ? config.getGenerators(json.logs).apply(args, contextPrime, assumed)
|
465
|
+
generatedParenthesized = contextPrime.isResponse ? config.getGenerators(json.logs).apply({...args, assumed}, contextPrime, assumed) : ''
|
455
466
|
config.parenthesized = false
|
456
467
|
}
|
457
468
|
// assumed = { paraphrase: true, response: false };
|
458
|
-
assumed = { paraphrase: true };
|
459
|
-
args.g = (c) => config.getGenerators(json.logs).apply(args, c, assumed)
|
460
|
-
args.
|
461
|
-
args.gr = (c) => config.getGenerators(json.logs).apply(args, {...c, paraphrase: false }, assumed)
|
462
|
-
args.gs = gs(args.g)
|
463
|
-
args.gsp = gs(args.gsp)
|
464
|
-
args.gsr = gs(args.gr)
|
469
|
+
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)
|
465
472
|
if (generateParenthesized) {
|
466
473
|
config.parenthesized = false
|
467
474
|
}
|
468
|
-
const paraphrases = config.getGenerators(json.logs).apply(args, contextPrime, assumed)
|
475
|
+
const paraphrases = config.getGenerators(json.logs).apply({...args, assumed}, contextPrime, assumed)
|
469
476
|
let paraphrasesParenthesized = []
|
470
477
|
if (generateParenthesized) {
|
471
478
|
config.parenthesized = true
|
472
|
-
paraphrasesParenthesized = config.getGenerators(json.logs).apply(args, contextPrime, assumed)
|
479
|
+
paraphrasesParenthesized = config.getGenerators(json.logs).apply({...args, assumed}, contextPrime, assumed)
|
473
480
|
config.parenthesized = false
|
474
481
|
}
|
475
|
-
args.g = (c) => config.getGenerators(json.logs).apply(args, c)
|
476
|
-
args.
|
477
|
-
args.gr = (c) => config.getGenerators(json.logs).apply(args, {...c, paraphrase: false })
|
478
|
-
args.gs = gs(args.g)
|
479
|
-
args.gsp = gs(args.gp)
|
480
|
-
args.gsr = gs(args.gr)
|
482
|
+
// args.g = (c) => config.getGenerators(json.logs).apply(args, c)
|
483
|
+
// args.gs = gs(args.g)
|
481
484
|
contextsPrime.push(contextPrime)
|
482
485
|
generatedPrime.push(generated)
|
483
486
|
paraphrasesPrime.push(paraphrases)
|
@@ -660,6 +663,7 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
|
|
660
663
|
opChoices: []
|
661
664
|
},
|
662
665
|
times: 0.0,
|
666
|
+
clientSideTimes: 0.0,
|
663
667
|
trace: '',
|
664
668
|
contexts: [],
|
665
669
|
generated: [],
|
@@ -701,8 +705,16 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
|
|
701
705
|
if (json.status !== 200) {
|
702
706
|
throw json
|
703
707
|
} else {
|
708
|
+
let clientSideTime
|
709
|
+
if (isTest) {
|
710
|
+
start = runtime.performance.performance.now()
|
711
|
+
}
|
704
712
|
const { contextsPrime, generatedPrime, paraphrasesPrime, paraphrasesParenthesizedPrime, generatedParenthesizedPrime, responsesPrime } =
|
705
713
|
processContextsB({ isTest, config, hierarchy, json, commandLineArgs /*, generators, semantics */ })
|
714
|
+
if (isTest) {
|
715
|
+
end = runtime.performance.performance.now()
|
716
|
+
clientSideTime = end - start
|
717
|
+
}
|
706
718
|
response.associations = json.associations
|
707
719
|
response.learned_contextual_priorities = json.learned_contextual_priorities
|
708
720
|
response.hierarchy = json.hierarchy
|
@@ -713,6 +725,7 @@ const _process = async (config, query, { initializer, commandLineArgs, credentia
|
|
713
725
|
// appendNoDups(response.metadata.priorities, json.metadata.priorities)
|
714
726
|
appendNoDups(response.metadata.opChoices, json.metadata.opChoices)
|
715
727
|
response.times += json.times
|
728
|
+
response.clientSideTimes += clientSideTime
|
716
729
|
response.trace = response.trace.concat(json.trace)
|
717
730
|
response.version = json.version
|
718
731
|
response.explain_priorities = json.explain_priorities
|
@@ -802,10 +815,10 @@ const runTest = async (config, expected, { args, verbose, testConfig, debug }) =
|
|
802
815
|
defaultInnerProcess(config, errorHandler, result)
|
803
816
|
}
|
804
817
|
if (verbose) {
|
805
|
-
const widths = [100,
|
818
|
+
const widths = [100, 60]
|
806
819
|
const lines = new Lines(widths)
|
807
820
|
lines.setElement(0, 0, test)
|
808
|
-
lines.setElement(0, 1, `time on server ${result.times.toFixed(2)}`)
|
821
|
+
lines.setElement(0, 1, `time on server: ${result.times.toFixed(2)} client: ${(result.clientSideTimes/1000).toFixed(2)}`)
|
809
822
|
lines.log()
|
810
823
|
}
|
811
824
|
const expected_objects = sortJson(convertToStable(expected.objects), { depth: 25 })
|
@@ -1323,6 +1336,7 @@ const rebuildTemplate = async ({ config, target, template, errorHandler = defaul
|
|
1323
1336
|
} else {
|
1324
1337
|
delete result.load_cache_time
|
1325
1338
|
delete result.times
|
1339
|
+
delete result.clientSideTimes
|
1326
1340
|
delete result.memory_free_percent
|
1327
1341
|
delete result.logs
|
1328
1342
|
delete result.version
|
@@ -1362,6 +1376,28 @@ const rebuildTemplate = async ({ config, target, template, errorHandler = defaul
|
|
1362
1376
|
await looper(Object.assign([], todo))
|
1363
1377
|
}
|
1364
1378
|
|
1379
|
+
const checkTemplate = (template) => {
|
1380
|
+
return
|
1381
|
+
if (!template) {
|
1382
|
+
return
|
1383
|
+
}
|
1384
|
+
if (template.checks) {
|
1385
|
+
throw new Error("The 'checks' property should be in the 'test' property not the 'template' property")
|
1386
|
+
}
|
1387
|
+
}
|
1388
|
+
|
1389
|
+
const checkTest = (testConfig) => {
|
1390
|
+
if (!testConfig) {
|
1391
|
+
return
|
1392
|
+
}
|
1393
|
+
if (!testConfig.name) {
|
1394
|
+
throw new Error("The 'test' property is missing the 'name' property that contains the name of the '<km>.test.json' file")
|
1395
|
+
}
|
1396
|
+
if (!testConfig.contents) {
|
1397
|
+
throw new Error("The 'test' property is missing the 'contents' property that contains contents of the '<km>.test.json' file")
|
1398
|
+
}
|
1399
|
+
}
|
1400
|
+
|
1365
1401
|
const knowledgeModule = async ({
|
1366
1402
|
module: moduleFromJSFile,
|
1367
1403
|
description,
|
@@ -1395,9 +1431,10 @@ const knowledgeModule = async ({
|
|
1395
1431
|
if (!description) {
|
1396
1432
|
throw new Error("'description' is a required parameter. The value should the description of the knowledge module.")
|
1397
1433
|
}
|
1398
|
-
if (!
|
1434
|
+
if (!testConfig) {
|
1399
1435
|
throw new Error("'test' is a required parameter. The value should the path to the file used to store the tests of the knowledge module and the contents of the file in the form { name: <filePath>, contexts: <json> }.")
|
1400
1436
|
}
|
1437
|
+
checkTest(testConfig)
|
1401
1438
|
|
1402
1439
|
const isProcess = require.main === moduleFromJSFile
|
1403
1440
|
|
@@ -1666,6 +1703,8 @@ const knowledgeModule = async ({
|
|
1666
1703
|
}
|
1667
1704
|
}
|
1668
1705
|
|
1706
|
+
checkTemplate(template)
|
1707
|
+
|
1669
1708
|
if (template) {
|
1670
1709
|
const needsRebuild = config.needsRebuild(template.template, template.instance, options)
|
1671
1710
|
if (needsRebuild) {
|
@@ -1674,7 +1713,9 @@ const knowledgeModule = async ({
|
|
1674
1713
|
config.config.rebuild = true
|
1675
1714
|
}
|
1676
1715
|
config.load(template.template, template.instance, { rebuild: needsRebuild })
|
1677
|
-
|
1716
|
+
if (!args.query) {
|
1717
|
+
printConfig()
|
1718
|
+
}
|
1678
1719
|
if (needsRebuild) {
|
1679
1720
|
return
|
1680
1721
|
}
|
@@ -1687,7 +1728,6 @@ const knowledgeModule = async ({
|
|
1687
1728
|
if (args.test || args.testVerbose || args.testAllVerbose || args.save) {
|
1688
1729
|
global.transitoryMode = true
|
1689
1730
|
}
|
1690
|
-
|
1691
1731
|
if (!args.query && !args.test && !args.info && (args.save || args.saveDeveloper)) {
|
1692
1732
|
global.transitoryMode = true
|
1693
1733
|
saveTests(config, test, testConfig, args.saveDeveloper)
|
@@ -1709,7 +1749,6 @@ const knowledgeModule = async ({
|
|
1709
1749
|
useTestConfig = config.getConfigs()[args.testModuleName].getTestConfig()
|
1710
1750
|
useTestConfig.testModuleName = args.testModuleName
|
1711
1751
|
test = useTestConfig.name
|
1712
|
-
|
1713
1752
|
}
|
1714
1753
|
runTests(config, test, { args, debug: args.debug, testConfig: useTestConfig, verbose: args.testVerbose || args.testAllVerbose, stopAtFirstError: !args.testAllVerbose }).then((results) => {
|
1715
1754
|
let newError = false
|
@@ -1758,12 +1797,16 @@ const knowledgeModule = async ({
|
|
1758
1797
|
show('paraphrases', result.expected.paraphrases, result.actual.paraphrases)
|
1759
1798
|
if (!args.testNoParenthesized) {
|
1760
1799
|
show('paraphrases parenthesized', result.expected.paraphrasesParenthesized, result.actual.paraphrasesParenthesized)
|
1800
|
+
if (args.vimdiff) {
|
1801
|
+
vimdiff(result.actual.paraphrasesParenthesized, result.expected.paraphrasesParenthesized)
|
1802
|
+
}
|
1803
|
+
}
|
1804
|
+
/*
|
1761
1805
|
}
|
1762
1806
|
show('responses', result.expected.responses, result.actual.responses)
|
1763
1807
|
if (!args.testNoParenthesized) {
|
1764
1808
|
show('responses parenthesized', result.expected.generatedParenthesized, result.actual.generatedParenthesized)
|
1765
1809
|
}
|
1766
|
-
/*
|
1767
1810
|
if (JSON.stringify(result.expected.paraphrases) !== JSON.stringify(result.actual.paraphrases)) {
|
1768
1811
|
if (!headerShown) {
|
1769
1812
|
console.log(' Failure')
|
@@ -1827,16 +1870,18 @@ const knowledgeModule = async ({
|
|
1827
1870
|
}
|
1828
1871
|
}
|
1829
1872
|
}
|
1830
|
-
if (
|
1873
|
+
if (hasError) {
|
1874
|
+
if (!headerShown) {
|
1875
|
+
if (!(useTestConfig.check && useTestConfig.check.length > 0)) {
|
1876
|
+
console.log('There are failures due to things other than paraphrases, responses and checked properties being different. They are not shown because you ran -tv or -tva which only shows difference in paraphrase and results. Usually what I do is -s and do a diff to make sure there are no other problems. If the paraphrases or results were different they would have shown here.')
|
1877
|
+
}
|
1878
|
+
}
|
1831
1879
|
if (!(useTestConfig.check && useTestConfig.check.length > 0)) {
|
1832
|
-
console.log('
|
1880
|
+
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.')
|
1881
|
+
// console.log(JSON.stringify(contexts))
|
1882
|
+
console.log('**************************** ERRORS ************************')
|
1833
1883
|
}
|
1834
1884
|
}
|
1835
|
-
if (!(useTestConfig.check && useTestConfig.check.length > 0)) {
|
1836
|
-
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.')
|
1837
|
-
// console.log(JSON.stringify(contexts))
|
1838
|
-
console.log('**************************** ERRORS ************************')
|
1839
|
-
}
|
1840
1885
|
}
|
1841
1886
|
// const contexts = { failures: results }
|
1842
1887
|
l(n - 1, hasError || newError)
|
package/package.json
CHANGED
package/runtime.js
CHANGED
package/src/flatten.js
CHANGED
package/src/generators.js
CHANGED
@@ -73,7 +73,8 @@ class Generator {
|
|
73
73
|
return matches
|
74
74
|
}
|
75
75
|
|
76
|
-
apply (baseArgs, objects, g, gs, context, hierarchy, config, response, log, options = {}) {
|
76
|
+
// apply (baseArgs, objects, g, gs, context, hierarchy, config, response, log, options = {}) {
|
77
|
+
apply (baseArgs, objects, context, hierarchy, config, response, log, options = {}) {
|
77
78
|
if (!log) {
|
78
79
|
throw new Error('generators.apply argument log is required')
|
79
80
|
}
|
@@ -103,12 +104,12 @@ class Generator {
|
|
103
104
|
log,
|
104
105
|
global:
|
105
106
|
objects,
|
106
|
-
g,
|
107
|
+
// g,
|
107
108
|
n,
|
108
109
|
hierarchy,
|
109
110
|
context,
|
110
111
|
uuid: this.uuid,
|
111
|
-
gs,
|
112
|
+
// gs,
|
112
113
|
config,
|
113
114
|
response,
|
114
115
|
api: this.getAPI(config),
|
@@ -165,136 +166,125 @@ class Generators {
|
|
165
166
|
this.logs = logs
|
166
167
|
};
|
167
168
|
|
168
|
-
// assumed - properties added to
|
169
|
-
apply (args,
|
169
|
+
// assumed - properties added to context before the generators are called. For setting paraphrase property
|
170
|
+
apply (args, context, assumed = {}, options = {}) {
|
171
|
+
if (Array.isArray(context)) {
|
172
|
+
return new Error("Expected a context not an array")
|
173
|
+
}
|
174
|
+
if (typeof context !== 'object') {
|
175
|
+
return String(context)
|
176
|
+
}
|
177
|
+
|
170
178
|
const config = args.config
|
171
179
|
const objects = args.objects
|
172
180
|
const hierarchy = args.hierarchy
|
173
181
|
const response = args.response
|
174
|
-
if (Array.isArray(contexts)) {
|
175
|
-
// no-op
|
176
|
-
} else if (typeof contexts === 'object') {
|
177
|
-
contexts = [contexts]
|
178
|
-
} else {
|
179
|
-
return String(contexts)
|
180
|
-
}
|
181
182
|
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
const
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
const help = 'The error has a retryCall property that will recall the function that failed.'
|
211
|
-
if (e.stack && e.message) {
|
212
|
-
const info = `${generator.notes ? generator.notes : ''}${generator.where ? generator.where : ''}`
|
213
|
-
errorMessage = `Error applying generator '${info}. Error is ${e.toString()} stack is ${e.stack}. Generator is ${generator.toString()}. ${help}`
|
214
|
-
} else if (e.error) {
|
215
|
-
const info = `${generator.notes ? generator.notes : ''}${generator.where ? generator.where : ''}`
|
216
|
-
errorMessage = `Error applying generator '${info}. Error is ${e.error.join()}. Generator is ${generator.toString()}. ${help}`
|
217
|
-
} else {
|
218
|
-
errorMessage = e.toString()
|
219
|
-
}
|
183
|
+
|
184
|
+
// args = { ...args, ...args.getAssumedScoped(assumed) }
|
185
|
+
args.addAssumedScoped(args, assumed)
|
186
|
+
context = Object.assign({}, context, args.assumed)
|
187
|
+
let generated = ''
|
188
|
+
let applied = false
|
189
|
+
const stack = args.calls.push()
|
190
|
+
for (let igenerator = 0; igenerator < this.generators.length; ++igenerator) {
|
191
|
+
const generator = this.generators[igenerator]
|
192
|
+
if (generator.matches(args, objects, context, hierarchy, config, options)) {
|
193
|
+
const log = (message) => { this.logs.push(message) }
|
194
|
+
// this.logs.push(`Generators: applied ${generator.toString()}\n to\n ${JSON.stringify(context)}`)
|
195
|
+
let errorMessage = 'The apply function did not return a value'
|
196
|
+
try {
|
197
|
+
generated= generator.apply(args, objects, context, hierarchy, config, response, log)
|
198
|
+
} catch( e ) {
|
199
|
+
// the next if handle this
|
200
|
+
generated = null
|
201
|
+
e.retryCall = () => generator.apply(args, objects, context, hierarchy, config, response, log)
|
202
|
+
const help = 'The error has a retryCall property that will recall the function that failed.'
|
203
|
+
if (e.stack && e.message) {
|
204
|
+
const info = `${generator.notes ? generator.notes : ''}${generator.where ? generator.where : ''}`
|
205
|
+
errorMessage = `Error applying generator '${info}. Error is ${e.toString()} stack is ${e.stack}. Generator is ${generator.toString()}. ${help}`
|
206
|
+
} else if (e.error) {
|
207
|
+
const info = `${generator.notes ? generator.notes : ''}${generator.where ? generator.where : ''}`
|
208
|
+
errorMessage = `Error applying generator '${info}. Error is ${e.error.join()}. Generator is ${generator.toString()}. ${help}`
|
209
|
+
} else {
|
210
|
+
errorMessage = e.toString()
|
220
211
|
}
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
}
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
}
|
257
|
-
lines.newRow()
|
258
|
-
lines.setElement(0, 1, 'APPLIED')
|
212
|
+
}
|
213
|
+
if (!generated && generated !== '') {
|
214
|
+
const widths = [10, 10, 90]
|
215
|
+
const lines = new Lines(widths)
|
216
|
+
lines.setElement(0, 0, 'Generator')
|
217
|
+
const source = `${generator.km}/#${generator.index}`
|
218
|
+
lines.setElement(0, 2, `ERROR while applying (${source}) ${generator.toLabel()}`)
|
219
|
+
lines.newRow()
|
220
|
+
lines.setElement(0, 2, generator.toString())
|
221
|
+
lines.newRow()
|
222
|
+
lines.setElement(0, 1, 'TO')
|
223
|
+
lines.setElement(0, 2, `(HASHCODE ${helpers.hashCode(JSON.stringify(helpers.sortJson(context, { depth: 25 })))})`)
|
224
|
+
lines.setElement(1, 2, JSON.stringify(helpers.sortJson(context, { depth: 25 }), null, 2))
|
225
|
+
lines.newRow()
|
226
|
+
lines.setElement(0, 1, 'STACK')
|
227
|
+
lines.setElement(0, 2, stack)
|
228
|
+
lines.newRow()
|
229
|
+
lines.setElement(0, 1, 'DEBUG')
|
230
|
+
lines.setElement(0, 2, `To debug this use args.callId == '${args.calls.current()}'`)
|
231
|
+
lines.newRow()
|
232
|
+
lines.setElement(0, 1, 'ERROR')
|
233
|
+
lines.setElement(0, 2, errorMessage)
|
234
|
+
this.logs.push(lines.toString())
|
235
|
+
const message = `ERROR while applying (${source}) ${generator.toLabel()}\n to\n ${JSON.stringify(context, null, 2)}.\n${errorMessage}'`
|
236
|
+
// this.logs.push(message)
|
237
|
+
// return [message]
|
238
|
+
args.calls.pop()
|
239
|
+
throw { error: [message], logs: this.logs }
|
240
|
+
}
|
241
|
+
if (((config || {}).config || {}).debug) {
|
242
|
+
const widths = [10, 10, 90]
|
243
|
+
const lines = new Lines(widths)
|
244
|
+
lines.setElement(0, 0, 'Generator')
|
245
|
+
if (generator.index > -1 && generator.km) {
|
246
|
+
// lines.setElement(0, 2, `KM '${generator.km}' ordinal: ${generator.index}`)
|
259
247
|
lines.setElement(0, 2, generator.toLabel())
|
260
|
-
lines.newRow()
|
261
|
-
lines.setElement(0, 2, generator.toString())
|
262
|
-
lines.newRow()
|
263
|
-
lines.setElement(0, 1, 'RESULT')
|
264
|
-
lines.setElement(0, 2, generated)
|
265
|
-
lines.newRow()
|
266
|
-
lines.setElement(0, 1, 'STACK')
|
267
|
-
lines.setElement(0, 2, stack)
|
268
|
-
lines.newRow()
|
269
|
-
lines.setElement(0, 1, 'DEBUG')
|
270
|
-
lines.setElement(0, 2, `To debug this use args.callId == '${args.calls.current()}'`)
|
271
|
-
lines.newRow()
|
272
|
-
lines.setElement(0, 1, 'TO')
|
273
|
-
lines.setElement(0, 2, `(HASHCODE ${helpers.hashCode(JSON.stringify(helpers.sortJson(context, { depth: 25 })))})`)
|
274
|
-
lines.setElement(1, 2, JSON.stringify(helpers.sortJson(context, { depth: 25 }), null, 2))
|
275
|
-
this.logs.push(lines.toString())
|
276
248
|
}
|
277
|
-
|
278
|
-
|
249
|
+
lines.newRow()
|
250
|
+
lines.setElement(0, 1, 'APPLIED')
|
251
|
+
lines.setElement(0, 2, generator.toLabel())
|
252
|
+
lines.newRow()
|
253
|
+
lines.setElement(0, 2, generator.toString())
|
254
|
+
lines.newRow()
|
255
|
+
lines.setElement(0, 1, 'RESULT')
|
256
|
+
lines.setElement(0, 2, generated)
|
257
|
+
lines.newRow()
|
258
|
+
lines.setElement(0, 1, 'STACK')
|
259
|
+
lines.setElement(0, 2, stack)
|
260
|
+
lines.newRow()
|
261
|
+
lines.setElement(0, 1, 'DEBUG')
|
262
|
+
lines.setElement(0, 2, `To debug this use args.callId == '${args.calls.current()}'`)
|
263
|
+
lines.newRow()
|
264
|
+
lines.setElement(0, 1, 'TO')
|
265
|
+
lines.setElement(0, 2, `(HASHCODE ${helpers.hashCode(JSON.stringify(helpers.sortJson(context, { depth: 25 })))})`)
|
266
|
+
lines.setElement(1, 2, JSON.stringify(helpers.sortJson(context, { depth: 25 }), null, 2))
|
267
|
+
this.logs.push(lines.toString())
|
279
268
|
}
|
269
|
+
applied = true
|
270
|
+
break
|
280
271
|
}
|
281
|
-
args.calls.pop()
|
282
|
-
if (!applied && ((config || {}).config || {}).debug) {
|
283
|
-
const widths = [10, 10, 90]
|
284
|
-
const lines = new Lines(widths)
|
285
|
-
lines.setElement(0, 0, 'Generator')
|
286
|
-
lines.setElement(0, 2, 'No generator applied')
|
287
|
-
lines.newRow()
|
288
|
-
lines.setElement(0, 1, 'STACK')
|
289
|
-
lines.setElement(0, 2, stack)
|
290
|
-
lines.newRow()
|
291
|
-
lines.setElement(0, 1, 'TO')
|
292
|
-
lines.setElement(0, 2, JSON.stringify(context, null, 2))
|
293
|
-
this.logs.push(lines.toString())
|
294
|
-
}
|
295
|
-
contextsPrime.push((config || {}).parenthesized ? "(" + generated + ")" : generated)
|
296
272
|
}
|
297
|
-
|
273
|
+
args.calls.pop()
|
274
|
+
if (!applied && ((config || {}).config || {}).debug) {
|
275
|
+
const widths = [10, 10, 90]
|
276
|
+
const lines = new Lines(widths)
|
277
|
+
lines.setElement(0, 0, 'Generator')
|
278
|
+
lines.setElement(0, 2, 'No generator applied')
|
279
|
+
lines.newRow()
|
280
|
+
lines.setElement(0, 1, 'STACK')
|
281
|
+
lines.setElement(0, 2, stack)
|
282
|
+
lines.newRow()
|
283
|
+
lines.setElement(0, 1, 'TO')
|
284
|
+
lines.setElement(0, 2, JSON.stringify(context, null, 2))
|
285
|
+
this.logs.push(lines.toString())
|
286
|
+
}
|
287
|
+
return ((config || {}).parenthesized ? "(" + generated + ")" : generated)
|
298
288
|
}
|
299
289
|
}
|
300
290
|
|