theprogrammablemind 9.8.0-beta.10 → 9.8.0-beta.11
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 +4 -13
- package/lines.js +1 -1
- package/package.json +1 -1
- package/src/config.js +28 -50
- package/src/configHelpers.js +36 -30
- package/src/fragments.js +17 -1
- package/src/generators.js +6 -6
- package/src/helpers.js +9 -10
- package/src/semantics.js +11 -5
package/client.js
CHANGED
|
@@ -158,13 +158,6 @@ const writeTest = (fn, query, objects, generated, paraphrases, responses, contex
|
|
|
158
158
|
if (runtime.fs.existsSync(fn)) {
|
|
159
159
|
tests = JSON.parse(runtime.fs.readFileSync(fn))
|
|
160
160
|
}
|
|
161
|
-
/*
|
|
162
|
-
for (const association of associations) {
|
|
163
|
-
association.sort()
|
|
164
|
-
}
|
|
165
|
-
associations.sort()
|
|
166
|
-
*/
|
|
167
|
-
// tests[query] = sortJson({ paraphrases, responses, contexts, objects: convertToStable(objects), associations, metadata, config, developerTest: saveDeveloper }, { depth: 25 })
|
|
168
161
|
const results = sortJson({
|
|
169
162
|
query,
|
|
170
163
|
summaries,
|
|
@@ -189,7 +182,6 @@ const writeTest = (fn, query, objects, generated, paraphrases, responses, contex
|
|
|
189
182
|
if (!wasSet) {
|
|
190
183
|
tests.push(results)
|
|
191
184
|
}
|
|
192
|
-
// fs.writeFileSync(fn, stringify(tests, { space: 2 }), { encoding: 'utf8', flag: 'w+' })
|
|
193
185
|
writeTestFile(fn, tests)
|
|
194
186
|
}
|
|
195
187
|
|
|
@@ -258,7 +250,7 @@ const throwErrorHandler = (error) => {
|
|
|
258
250
|
throw error
|
|
259
251
|
}
|
|
260
252
|
|
|
261
|
-
const _process = async (config, query, { queryNumber, initializer, commandLineArgs, credentials, writeTests, logs, isProcess, isModule, isTest, saveDeveloper, rebuildingTemplate, testConfig, testsFN, errorHandler = throwErrorHandler } = {}) => {
|
|
253
|
+
const _process = async (config, query, { isFragment, queryNumber, initializer, commandLineArgs, credentials, writeTests, logs, isProcess, isModule, isTest, saveDeveloper, rebuildingTemplate, testConfig, testsFN, errorHandler = throwErrorHandler } = {}) => {
|
|
262
254
|
if (credentials) {
|
|
263
255
|
config.server(credentials.server, credentials.key)
|
|
264
256
|
}
|
|
@@ -364,7 +356,7 @@ const _process = async (config, query, { queryNumber, initializer, commandLineAr
|
|
|
364
356
|
const summary = { summaries: json.summaries, length: json.contexts.length }
|
|
365
357
|
summaries.push(summary)
|
|
366
358
|
const { updatedContextIdCounter, contextsPrime, generatedPrime, paraphrasesPrime, paraphrasesParenthesizedPrime, generatedParenthesizedPrime, responsesPrime } =
|
|
367
|
-
await processContextsB({ contextIdCounter, logs, calls, isTest, isProcess, isModule, rebuildingTemplate, config, hierarchy, json, commandLineArgs /*, generators, semantics */ })
|
|
359
|
+
await processContextsB({ skipSemantics: isFragment, isFragment, contextIdCounter, logs, calls, isTest, isProcess, isModule, rebuildingTemplate, config, hierarchy, json, commandLineArgs /*, generators, semantics */ })
|
|
368
360
|
contextIdCounter = updatedContextIdCounter
|
|
369
361
|
if (isTest) {
|
|
370
362
|
const end = runtime.performance.performance.now()
|
|
@@ -384,7 +376,6 @@ const _process = async (config, query, { queryNumber, initializer, commandLineAr
|
|
|
384
376
|
response.explain_associations_details = (response.explain_associations_details || []).concat(json.explain_associations_details)
|
|
385
377
|
response.explain_associations_trie = json.explain_associations_trie
|
|
386
378
|
response.contextual_priorities_ambiguities = json.contextual_priorities_ambiguities
|
|
387
|
-
// response.rtf_associations = json.rtf_associations
|
|
388
379
|
|
|
389
380
|
response.contexts = response.contexts.concat(contextsPrime)
|
|
390
381
|
response.generated = response.generated.concat(generatedPrime)
|
|
@@ -1036,7 +1027,7 @@ const rebuildTemplate = async ({ config, instance, target, previousResultss, reb
|
|
|
1036
1027
|
await loadInstance(config, { resultss: [results] })
|
|
1037
1028
|
} else {
|
|
1038
1029
|
try {
|
|
1039
|
-
results = await _process(config, query.query, { initializer, rebuildingTemplate: true })
|
|
1030
|
+
results = await _process(config, query.query, { initializer, rebuildingTemplate: true, isFragment })
|
|
1040
1031
|
} catch (e) {
|
|
1041
1032
|
if (e.summaries && e.summaries.length > 0) {
|
|
1042
1033
|
suggestFix(e.summaries)
|
|
@@ -1064,7 +1055,7 @@ const rebuildTemplate = async ({ config, instance, target, previousResultss, reb
|
|
|
1064
1055
|
results.isFragment = isFragment
|
|
1065
1056
|
results.skipSemantics = skipSemantics
|
|
1066
1057
|
results.development = query.development
|
|
1067
|
-
results.key = { query: query.query, hierarchy }
|
|
1058
|
+
results.key = { query: query.query, hierarchy, preserve: query.preserve }
|
|
1068
1059
|
accumulators[property].push(results)
|
|
1069
1060
|
if (isFragment) {
|
|
1070
1061
|
config.fragmentsBeingBuilt.push({ query: query.query, contexts: results.contexts })
|
package/lines.js
CHANGED
package/package.json
CHANGED
package/src/config.js
CHANGED
|
@@ -390,7 +390,7 @@ const handleBridgeProps = (config, bridge, { addFirst, uuid } = {}) => {
|
|
|
390
390
|
|
|
391
391
|
if (!bridge.where) {
|
|
392
392
|
if (bridge.generator || bridge.generatorp || bridge.generatorr || bridge.generator ||
|
|
393
|
-
bridge.semantic || bridge.
|
|
393
|
+
bridge.semantic || bridge.semantics) {
|
|
394
394
|
throw new Error(`In the KM "${config.name}", for the bridge ${bridge.id} the where property is missing. Use where: where().`)
|
|
395
395
|
}
|
|
396
396
|
}
|
|
@@ -494,18 +494,10 @@ const handleBridgeProps = (config, bridge, { addFirst, uuid } = {}) => {
|
|
|
494
494
|
applyWrapped: semantic,
|
|
495
495
|
}
|
|
496
496
|
} else {
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
applyWrapped: semantic,
|
|
502
|
-
}
|
|
503
|
-
} else {
|
|
504
|
-
semanticDef = {
|
|
505
|
-
match: (args) => bridge.id === args.context.marker && !!args.context.evaluate === evaluate && match(args),
|
|
506
|
-
apply: (args) => apply(args),
|
|
507
|
-
applyWrapped: semantic,
|
|
508
|
-
}
|
|
497
|
+
semanticDef = {
|
|
498
|
+
match: (args) => bridge.id === args.context.marker && match(args),
|
|
499
|
+
apply: (args) => apply(args),
|
|
500
|
+
applyWrapped: semantic,
|
|
509
501
|
}
|
|
510
502
|
}
|
|
511
503
|
semanticDef.where = semantic.where || bridge.where || helpers.where(4)
|
|
@@ -521,28 +513,10 @@ const handleBridgeProps = (config, bridge, { addFirst, uuid } = {}) => {
|
|
|
521
513
|
}
|
|
522
514
|
}
|
|
523
515
|
|
|
524
|
-
if (bridge.evaluator) {
|
|
525
|
-
addSemantic(bridge.evaluator, true, 'evaluator')
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
if (bridge.evaluator2) {
|
|
529
|
-
addSemantic(bridge.evaluator2, false, 'evaluator2')
|
|
530
|
-
}
|
|
531
|
-
|
|
532
516
|
if (bridge.semantic) {
|
|
533
517
|
addSemantic(bridge.semantic, false, 'semantic')
|
|
534
518
|
}
|
|
535
519
|
|
|
536
|
-
if (bridge.evaluators) {
|
|
537
|
-
const evaluators = [...bridge.evaluators]
|
|
538
|
-
evaluators.reverse()
|
|
539
|
-
if (evaluators) {
|
|
540
|
-
for (const evaluator of evaluators) {
|
|
541
|
-
addSemantic(evaluator, true, 'evaluator')
|
|
542
|
-
}
|
|
543
|
-
}
|
|
544
|
-
}
|
|
545
|
-
|
|
546
520
|
if (bridge.semantics) {
|
|
547
521
|
const semantics = [...bridge.semantics]
|
|
548
522
|
semantics.reverse()
|
|
@@ -572,9 +546,6 @@ const handleCalculatedProps = (baseConfig, moreConfig, { addFirst, uuid } = {})
|
|
|
572
546
|
'convolution',
|
|
573
547
|
'disabled',
|
|
574
548
|
'enhanced_associations',
|
|
575
|
-
'evaluator',
|
|
576
|
-
'evaluator2',
|
|
577
|
-
'evaluators',
|
|
578
549
|
'generatorp',
|
|
579
550
|
'generatorpr',
|
|
580
551
|
'generatorr',
|
|
@@ -1047,6 +1018,7 @@ class Config {
|
|
|
1047
1018
|
return {
|
|
1048
1019
|
pseudo: true,
|
|
1049
1020
|
description: 'this is a pseudo config that has limited functionality due to being available in the initializer and fixtures function context',
|
|
1021
|
+
nextFragmentContextId: () => this.nextFragmentContextId(),
|
|
1050
1022
|
addAssociation: (...args) => this.addAssociation(...args),
|
|
1051
1023
|
addAssociations: (...args) => this.addAssociations(...args),
|
|
1052
1024
|
addBridge: (...args) => this.addBridge(...args, uuid),
|
|
@@ -1261,7 +1233,7 @@ class Config {
|
|
|
1261
1233
|
|
|
1262
1234
|
warningNotEvaluated (log, value) {
|
|
1263
1235
|
const description = 'WARNING: for semantics, implement an evaluations handler, set "value" property of the operator to the value.'
|
|
1264
|
-
const match = `({context}) => context.marker === '${value.marker}' &&
|
|
1236
|
+
const match = `({context}) => context.marker === '${value.marker}' && <other conditions as you like>`
|
|
1265
1237
|
const apply = '({context}) => <do stuff...>; context.value = <value>'
|
|
1266
1238
|
const input = indent(JSON.stringify(value, null, 2), 2)
|
|
1267
1239
|
const message = `${description}\nThe semantic would be\n match: ${match}\n apply: ${apply}\nThe input context would be:\n${input}\n`
|
|
@@ -1270,18 +1242,15 @@ class Config {
|
|
|
1270
1242
|
|
|
1271
1243
|
// value is in response field
|
|
1272
1244
|
// TODO maybe generalize out query+evaluate along the lines of set value and set reference
|
|
1273
|
-
async
|
|
1274
|
-
const
|
|
1275
|
-
|
|
1276
|
-
if (
|
|
1277
|
-
|
|
1245
|
+
async evaluate (args, logs, context) {
|
|
1246
|
+
const apply = (c) => this.getSemantics(logs).apply(args, c)
|
|
1247
|
+
const instance = await apply(context)
|
|
1248
|
+
if (typeof instance !== 'string') {
|
|
1249
|
+
args.calls.touch(instance)
|
|
1278
1250
|
}
|
|
1279
|
-
if (instance.evalue == null) {
|
|
1280
|
-
|
|
1281
|
-
instance.edefault = true
|
|
1251
|
+
if (instance.evalue == null && !instance.verbatim && !instance.value) {
|
|
1252
|
+
this.warningNotEvaluated(logs, context)
|
|
1282
1253
|
}
|
|
1283
|
-
delete instance.evaluate
|
|
1284
|
-
instance.instance = true
|
|
1285
1254
|
return instance
|
|
1286
1255
|
}
|
|
1287
1256
|
|
|
@@ -1312,10 +1281,14 @@ class Config {
|
|
|
1312
1281
|
let fi = fragmentInstantiator(args, fragment.contexts)
|
|
1313
1282
|
if (mappings) {
|
|
1314
1283
|
fi = await fi
|
|
1315
|
-
|
|
1284
|
+
const instantiated = await fi.instantiate([{
|
|
1316
1285
|
match: ({context}) => !!mappings[context.value], // is the value in the mappings
|
|
1317
1286
|
apply: ({context}) => Object.assign(context, mappings[context.value]),
|
|
1318
|
-
}])
|
|
1287
|
+
}], fragment.key?.preserve)
|
|
1288
|
+
if (process.env.DEBUG_CONTEXT_ID && process.env.DEBUG_CONTEXT_ID == instantiated.context_id) {
|
|
1289
|
+
debugger
|
|
1290
|
+
}
|
|
1291
|
+
return instantiated
|
|
1319
1292
|
} else {
|
|
1320
1293
|
return fi
|
|
1321
1294
|
}
|
|
@@ -1415,9 +1388,6 @@ class Config {
|
|
|
1415
1388
|
delete bridge.generatorp
|
|
1416
1389
|
delete bridge.generatorr
|
|
1417
1390
|
delete bridge.generatorpr
|
|
1418
|
-
delete bridge.evaluator
|
|
1419
|
-
delete bridge.evaluator2
|
|
1420
|
-
delete bridge.evaluators
|
|
1421
1391
|
delete bridge.semantic
|
|
1422
1392
|
delete bridge.semantics
|
|
1423
1393
|
if (false && !bridge.bridge) {
|
|
@@ -2199,6 +2169,12 @@ class Config {
|
|
|
2199
2169
|
// await this.demoInitializer(this)
|
|
2200
2170
|
}
|
|
2201
2171
|
|
|
2172
|
+
nextFragmentContextId() {
|
|
2173
|
+
const id = this.fragmentNextContextId
|
|
2174
|
+
this.fragmentNextContextId = this.fragmentNextContextId + 1
|
|
2175
|
+
return id
|
|
2176
|
+
}
|
|
2177
|
+
|
|
2202
2178
|
// configs = [ { config, namespace } ... ]
|
|
2203
2179
|
constructor (config, module, clientProcess, apiKMs, rootIsProcess, testingModuleName) {
|
|
2204
2180
|
if (config instanceof Config) {
|
|
@@ -2209,6 +2185,8 @@ class Config {
|
|
|
2209
2185
|
apiKMs = []
|
|
2210
2186
|
}
|
|
2211
2187
|
|
|
2188
|
+
this.fragmentNextContextId = 1000
|
|
2189
|
+
|
|
2212
2190
|
if (config) {
|
|
2213
2191
|
validConfigProps(config)
|
|
2214
2192
|
|
package/src/configHelpers.js
CHANGED
|
@@ -1,7 +1,24 @@
|
|
|
1
|
-
const { InitCalls } = require('./helpers')
|
|
1
|
+
const { InitCalls, where } = require('./helpers')
|
|
2
2
|
const DigraphInternal = require('./digraph_internal')
|
|
3
3
|
const debug = require('./debug')
|
|
4
4
|
|
|
5
|
+
class ErrorReason extends Error {
|
|
6
|
+
constructor (context, stack) {
|
|
7
|
+
super(JSON.stringify(context))
|
|
8
|
+
this.reason = context
|
|
9
|
+
this.stack = stack
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
toString() {
|
|
13
|
+
if (this.reason) {
|
|
14
|
+
return this.reason
|
|
15
|
+
} else {
|
|
16
|
+
return super.toString()
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
|
|
5
22
|
const gs = (g) => async (contexts, separator, lastSeparator) => {
|
|
6
23
|
if (!Array.isArray(contexts)) {
|
|
7
24
|
throw new Error('Expected a list')
|
|
@@ -63,13 +80,6 @@ const isA = (hierarchy) => (child, parent, { strict = false } = {}) => {
|
|
|
63
80
|
}
|
|
64
81
|
}
|
|
65
82
|
|
|
66
|
-
class ErrorReason extends Error {
|
|
67
|
-
constructor (context) {
|
|
68
|
-
super(JSON.stringify(context))
|
|
69
|
-
this.reason = context
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
83
|
const cleanAssign = (dest, ...srcs) => {
|
|
74
84
|
for (const key in dest) {
|
|
75
85
|
let found = false
|
|
@@ -93,7 +103,7 @@ class HandlerStack {
|
|
|
93
103
|
}
|
|
94
104
|
|
|
95
105
|
push(handler) {
|
|
96
|
-
this.handlers.push(handler)
|
|
106
|
+
this.handlers.push(handler.where || handler)
|
|
97
107
|
}
|
|
98
108
|
|
|
99
109
|
pop() {
|
|
@@ -210,7 +220,7 @@ const setupArgs = (args, config, logs, hierarchy, uuidForScoping) => {
|
|
|
210
220
|
args.km = (name) => config.getConfig(name)
|
|
211
221
|
args.api = (name) => config.getConfig(name).api
|
|
212
222
|
args.error = (context) => {
|
|
213
|
-
throw new ErrorReason(context)
|
|
223
|
+
throw new ErrorReason(context, [...args.stack.handlers, where()])
|
|
214
224
|
}
|
|
215
225
|
args.kms = config.getConfigs()
|
|
216
226
|
args.config = config.getPseudoConfig(uuidForScoping, config)
|
|
@@ -278,24 +288,18 @@ const setupArgs = (args, config, logs, hierarchy, uuidForScoping) => {
|
|
|
278
288
|
const { assumed = {}, options = {} } = rest
|
|
279
289
|
return config.getGenerators(logs).apply(addAssumed(args, assumed, { paraphrase: false, isResponse: true }), { ...c, paraphrase: false, isResponse: true }, options)
|
|
280
290
|
}
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
return
|
|
286
|
-
}
|
|
287
|
-
return config.getEvaluator(args.s, args.calls, logs, c, { isModule: args.isModule, isProcess: args.isProcess })
|
|
291
|
+
|
|
292
|
+
args.e = (c, where) => {
|
|
293
|
+
if (!c) {
|
|
294
|
+
return
|
|
288
295
|
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
}
|
|
294
|
-
const s = (c, options = {}) => config.getSemantics(logs).apply(args, c, options)
|
|
295
|
-
return config.getEvaluator(s, args.calls, logs, c, { isModule: args.isModule, isProcess: args.isProcess })
|
|
296
|
+
if (where) {
|
|
297
|
+
return args.stack.wrap(() => config.evaluate(args, logs, c), where)
|
|
298
|
+
} else {
|
|
299
|
+
return config.evaluate(args, logs, c)
|
|
296
300
|
}
|
|
297
|
-
args.s = args.e
|
|
298
301
|
}
|
|
302
|
+
|
|
299
303
|
args.gs = gs(args.g)
|
|
300
304
|
args.gsp = gs(args.gp)
|
|
301
305
|
args.gsr = gs(args.gr)
|
|
@@ -380,7 +384,7 @@ const processContext = async (context, { objects = {}, config, logs = [] }) => {
|
|
|
380
384
|
return { context, generated, paraphrases, responses }
|
|
381
385
|
}
|
|
382
386
|
|
|
383
|
-
const setupProcessB = ({ config, initializer, allowDelta = false, rebuildingTemplate = false } = {}) => {
|
|
387
|
+
const setupProcessB = ({ config, initializer, isFragment, allowDelta = false, rebuildingTemplate = false } = {}) => {
|
|
384
388
|
const key = config._key
|
|
385
389
|
const data = Object.assign({ key, version: '3' }, { uuid: config._uuid })
|
|
386
390
|
/*
|
|
@@ -445,7 +449,7 @@ const setupContexts = (rawContexts) => {
|
|
|
445
449
|
return contexts
|
|
446
450
|
}
|
|
447
451
|
|
|
448
|
-
const processContextsB = async ({ config, calls, hierarchy, logs, semantics, generators, json, isTest, isProcess, isModule, rebuildingTemplate, isInstance, instance, query, data, retries, url, commandLineArgs, forTemplate, contextIdCounter }) => {
|
|
452
|
+
const processContextsB = async ({ skipSemantics, isFragment, config, calls, hierarchy, logs, semantics, generators, json, isTest, isProcess, isModule, rebuildingTemplate, isInstance, instance, query, data, retries, url, commandLineArgs, forTemplate, contextIdCounter }) => {
|
|
449
453
|
// TODO fix this name to contextsPrime
|
|
450
454
|
const contextsPrime = []
|
|
451
455
|
const generatedPrime = []
|
|
@@ -453,6 +457,7 @@ const processContextsB = async ({ config, calls, hierarchy, logs, semantics, gen
|
|
|
453
457
|
const paraphrasesParenthesizedPrime = []
|
|
454
458
|
const generatedParenthesizedPrime = []
|
|
455
459
|
const responsesPrime = []
|
|
460
|
+
|
|
456
461
|
const contexts = setupContexts(json.contexts)
|
|
457
462
|
|
|
458
463
|
const objects = config.get('objects')
|
|
@@ -474,7 +479,7 @@ const processContextsB = async ({ config, calls, hierarchy, logs, semantics, gen
|
|
|
474
479
|
throw new Error('There are errors in the logs. Run with the -d flag and grep for Error')
|
|
475
480
|
}
|
|
476
481
|
const generateParenthesized = isTest || (commandLineArgs && commandLineArgs.save)
|
|
477
|
-
if (!config.get('skipSemantics')) {
|
|
482
|
+
if (!config.get('skipSemantics') && !skipSemantics) {
|
|
478
483
|
const semantics = config.getSemantics(logs)
|
|
479
484
|
try {
|
|
480
485
|
contextPrime = await semantics.apply(args, context)
|
|
@@ -489,17 +494,18 @@ const processContextsB = async ({ config, calls, hierarchy, logs, semantics, gen
|
|
|
489
494
|
if (isInstance) {
|
|
490
495
|
console.log('error', e.error)
|
|
491
496
|
}
|
|
497
|
+
|
|
492
498
|
let reason = e.reason
|
|
493
499
|
if (!reason) {
|
|
494
500
|
if (e.error) {
|
|
495
501
|
reason = e.error[0]
|
|
496
502
|
}
|
|
497
503
|
}
|
|
504
|
+
|
|
498
505
|
contextPrime = await semantics.apply(args, {
|
|
499
506
|
marker: 'error',
|
|
500
507
|
context,
|
|
501
|
-
text: e
|
|
502
|
-
// reason: e.reason,
|
|
508
|
+
text: e.toString(),
|
|
503
509
|
reason,
|
|
504
510
|
error: e.stack || e.error
|
|
505
511
|
})
|
package/src/fragments.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const _ = require('lodash')
|
|
2
|
+
const debug = require('./debug')
|
|
2
3
|
const helpers = require('./helpers')
|
|
3
4
|
|
|
4
5
|
function createChangeTracker(obj) {
|
|
@@ -28,11 +29,23 @@ function fragmentInstantiator (args, contexts) {
|
|
|
28
29
|
contexts: () => {
|
|
29
30
|
return _.cloneDeep(contexts)
|
|
30
31
|
},
|
|
31
|
-
|
|
32
|
+
// preserve property not to be changed.
|
|
33
|
+
instantiate: async (mappings, preserve) => {
|
|
34
|
+
preserve = preserve || []
|
|
32
35
|
const instantiated = _.cloneDeep(contexts)
|
|
33
36
|
const todo = [{ context: instantiated, path: [] }]
|
|
34
37
|
args = { ...args }
|
|
35
38
|
args.pathEquals = helpers.pathEquals
|
|
39
|
+
const preserved = preserve.map((path) => {
|
|
40
|
+
if (contexts.length == 1) {
|
|
41
|
+
path = ['0', path]
|
|
42
|
+
}
|
|
43
|
+
const value = helpers.getByPath(contexts, path)
|
|
44
|
+
return { path, value }
|
|
45
|
+
})
|
|
46
|
+
for (const context of contexts) {
|
|
47
|
+
context.context_id = args.config.nextFragmentContextId()
|
|
48
|
+
}
|
|
36
49
|
while (todo.length > 0) {
|
|
37
50
|
const { context, path } = todo.pop()
|
|
38
51
|
const { proxy, getChanges } = createChangeTracker(context);
|
|
@@ -57,6 +70,9 @@ function fragmentInstantiator (args, contexts) {
|
|
|
57
70
|
}
|
|
58
71
|
}
|
|
59
72
|
}
|
|
73
|
+
for (const { path, value } of preserved) {
|
|
74
|
+
helpers.setByPath(instantiated, path, value)
|
|
75
|
+
}
|
|
60
76
|
if (contexts.length == 1 && instantiated.length == 1) {
|
|
61
77
|
return instantiated[0]
|
|
62
78
|
} else {
|
package/src/generators.js
CHANGED
|
@@ -225,18 +225,18 @@ class Generators {
|
|
|
225
225
|
const source = `${generator.km}/#${generator.index}`
|
|
226
226
|
lines.setElement(0, 2, `ERROR while applying (${source}) ${generator.toLabel()}`)
|
|
227
227
|
lines.newRow()
|
|
228
|
-
lines.setElement(0,
|
|
228
|
+
lines.setElement(0, 1, 'DEBUG')
|
|
229
|
+
lines.setElement(0, 2, `To debug this use debug.breakAt('${args.calls.current()}') or DEBUG_BREAKAT="${args.calls.current()}"`)
|
|
229
230
|
lines.newRow()
|
|
230
231
|
lines.setElement(0, 1, 'STACK')
|
|
231
232
|
lines.setElement(0, 2, stack)
|
|
232
233
|
lines.newRow()
|
|
234
|
+
lines.setElement(0, 2, generator.toString())
|
|
235
|
+
lines.newRow()
|
|
233
236
|
lines.setElement(0, 1, 'TO')
|
|
234
237
|
lines.setElement(0, 2, `context_id: ${context.context_id}`)
|
|
235
238
|
lines.setElement(1, 2, JSON.stringify(helpers.sortJson(context, { depth: 10 }), null, 2))
|
|
236
239
|
lines.newRow()
|
|
237
|
-
lines.setElement(0, 1, 'DEBUG')
|
|
238
|
-
lines.setElement(0, 2, `To debug this use debug.breakAt('${args.calls.current()}') or DEBUG_BREAKAT="${args.calls.current()}"`)
|
|
239
|
-
lines.newRow()
|
|
240
240
|
lines.setElement(0, 1, 'ERROR')
|
|
241
241
|
lines.setElement(0, 2, errorMessage)
|
|
242
242
|
this.logs.push(lines.toString())
|
|
@@ -259,14 +259,14 @@ class Generators {
|
|
|
259
259
|
lines.setElement(0, 1, 'APPLIED')
|
|
260
260
|
lines.setElement(0, 2, generator.toLabel())
|
|
261
261
|
lines.newRow()
|
|
262
|
-
lines.setElement(0, 2, generator.toString())
|
|
263
|
-
lines.newRow()
|
|
264
262
|
lines.setElement(0, 1, 'RESULT')
|
|
265
263
|
lines.setElement(0, 2, generated + " " + pOrRTag)
|
|
266
264
|
lines.newRow()
|
|
267
265
|
lines.setElement(0, 1, 'STACK')
|
|
268
266
|
lines.setElement(0, 2, stack)
|
|
269
267
|
lines.newRow()
|
|
268
|
+
lines.setElement(0, 2, generator.toString())
|
|
269
|
+
lines.newRow()
|
|
270
270
|
lines.setElement(0, 1, 'DEBUG')
|
|
271
271
|
lines.setElement(0, 2, `To debug this use debug.breakAt('${args.calls.current()}')`)
|
|
272
272
|
lines.newRow()
|
package/src/helpers.js
CHANGED
|
@@ -72,7 +72,14 @@ function where (goUp = 2) {
|
|
|
72
72
|
let match
|
|
73
73
|
for (line of lines.slice(1)) {
|
|
74
74
|
// if (!(line.includes('config.js:') || line.includes('client.js:') || line.includes('<anonymous>'))) {
|
|
75
|
-
|
|
75
|
+
const ignore = [
|
|
76
|
+
'config.js:',
|
|
77
|
+
'client.js:',
|
|
78
|
+
'helpers.js:',
|
|
79
|
+
'configHelpers.js:',
|
|
80
|
+
]
|
|
81
|
+
// if (!(line.includes('config.js:') || line.includes('client.js:') || line.includes('helpers.js:'))) {
|
|
82
|
+
if(!ignore.some(p => line.includes(p))) {
|
|
76
83
|
match = regexForm1.exec(line) || regexForm2.exec(line)
|
|
77
84
|
if (!match) {
|
|
78
85
|
continue
|
|
@@ -477,15 +484,6 @@ const functionsToStrings = (config) => {
|
|
|
477
484
|
if (bridge.semantics) {
|
|
478
485
|
bridge.semantics = bridge.semantics.toString()
|
|
479
486
|
}
|
|
480
|
-
if (bridge.evaluator) {
|
|
481
|
-
bridge.evaluator = bridge.evaluator.toString()
|
|
482
|
-
}
|
|
483
|
-
if (bridge.evaluator2) {
|
|
484
|
-
bridge.evaluator2 = bridge.evaluator2.toString()
|
|
485
|
-
}
|
|
486
|
-
if (bridge.evaluators) {
|
|
487
|
-
bridge.evaluators = bridge.evaluators.toString()
|
|
488
|
-
}
|
|
489
487
|
return bridge
|
|
490
488
|
})
|
|
491
489
|
}
|
|
@@ -718,4 +716,5 @@ module.exports = {
|
|
|
718
716
|
watchProperty,
|
|
719
717
|
pathEquals,
|
|
720
718
|
OverrideCheck,
|
|
719
|
+
normalizePath,
|
|
721
720
|
}
|
package/src/semantics.js
CHANGED
|
@@ -259,14 +259,14 @@ class Semantics {
|
|
|
259
259
|
const source = `${semantic.km}/#${semantic.index}`
|
|
260
260
|
lines.setElement(0, 2, `ERROR while applying (${source}) ${semantic.toLabel()}`)
|
|
261
261
|
lines.newRow()
|
|
262
|
-
lines.setElement(0, 2, semantic.toString())
|
|
263
|
-
lines.newRow()
|
|
264
262
|
lines.setElement(0, 1, 'DEBUG')
|
|
265
263
|
lines.setElement(0, 2, `To debug this use debug.breakAt('${args.calls.current()}') in the code or DEBUG_BREAKAT="${args.calls.current()}"`)
|
|
266
264
|
lines.newRow()
|
|
267
265
|
lines.setElement(0, 1, 'STACK')
|
|
268
266
|
lines.setElement(0, 2, stack)
|
|
269
267
|
lines.newRow()
|
|
268
|
+
lines.setElement(0, 2, semantic.toString())
|
|
269
|
+
lines.newRow()
|
|
270
270
|
lines.setElement(0, 1, 'TO')
|
|
271
271
|
lines.setElement(0, 2, `context_id: ${context.context_id}`)
|
|
272
272
|
lines.setElement(1, 2, JSON.stringify(helpers.sortJson(context, { depth: 25 }), null, 2))
|
|
@@ -277,6 +277,9 @@ class Semantics {
|
|
|
277
277
|
const message = `ERROR while applying (${source}) ${semantic.toLabel()}\n to\n ${JSON.stringify(context, null, 2)}.\n${errorMessage}'`
|
|
278
278
|
// this.logs.push(message)
|
|
279
279
|
// return [message]
|
|
280
|
+
if (e.reason) {
|
|
281
|
+
throw e
|
|
282
|
+
}
|
|
280
283
|
args.calls.pop()
|
|
281
284
|
throw { error: [message], logs: this.logs, reason: e.reason }
|
|
282
285
|
}
|
|
@@ -295,14 +298,14 @@ class Semantics {
|
|
|
295
298
|
lines.setElement(0, 1, 'APPLIED')
|
|
296
299
|
lines.setElement(0, 2, semantic.toLabel())
|
|
297
300
|
lines.newRow()
|
|
298
|
-
lines.setElement(0, 2, semantic.toString())
|
|
299
|
-
lines.newRow()
|
|
300
301
|
lines.setElement(0, 1, 'DEBUG')
|
|
301
302
|
lines.setElement(0, 2, `To debug this use debug.breakAt('${args.calls.current()}') in the code or DEBUG_BREAKAT="${args.calls.current()}"`)
|
|
302
303
|
lines.newRow()
|
|
303
304
|
lines.setElement(0, 1, 'STACK')
|
|
304
305
|
lines.setElement(0, 2, stack)
|
|
305
306
|
lines.newRow()
|
|
307
|
+
lines.setElement(0, 2, semantic.toString())
|
|
308
|
+
lines.newRow()
|
|
306
309
|
lines.setElement(0, 1, 'TO')
|
|
307
310
|
lines.setElement(0, 2, `context_id: ${context.context_id}`)
|
|
308
311
|
lines.setElement(1, 2, JSON.stringify(helpers.sortJson(context, { depth: 25 }), null, 2))
|
|
@@ -332,7 +335,6 @@ class Semantics {
|
|
|
332
335
|
for (const f of finallyList) {
|
|
333
336
|
await f()
|
|
334
337
|
}
|
|
335
|
-
args.calls.pop()
|
|
336
338
|
if (!applied && debug) {
|
|
337
339
|
const widths = Lines.addRemainder([10, 10])
|
|
338
340
|
const lines = new Lines(widths)
|
|
@@ -340,6 +342,9 @@ class Semantics {
|
|
|
340
342
|
lines.setElement(0, 1, `#${context.context_id || "?"}`)
|
|
341
343
|
lines.setElement(0, 2, 'No semantic applied')
|
|
342
344
|
lines.newRow()
|
|
345
|
+
lines.setElement(0, 1, 'DEBUG')
|
|
346
|
+
lines.setElement(0, 2, `To debug this use debug.breakAt('${args.calls.current()}') in the code or DEBUG_BREAKAT="${args.calls.current()}"`)
|
|
347
|
+
lines.newRow()
|
|
343
348
|
lines.setElement(0, 1, 'STACK')
|
|
344
349
|
lines.setElement(0, 2, stack)
|
|
345
350
|
lines.newRow()
|
|
@@ -348,6 +353,7 @@ class Semantics {
|
|
|
348
353
|
lines.setElement(1, 2, JSON.stringify(helpers.sortJson(context, { depth: 25 }), null, 2))
|
|
349
354
|
this.logs.push(lines.toString())
|
|
350
355
|
}
|
|
356
|
+
args.calls.pop()
|
|
351
357
|
return contextPrime
|
|
352
358
|
}
|
|
353
359
|
|