theprogrammablemind_4wp 9.5.1-beta.5 → 9.5.1-beta.7
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/lines.js +7 -0
- package/package.json +4 -3
- package/src/config.js +4 -36
- package/src/generators.js +3 -3
- package/src/helpers.js +59 -0
- package/src/semantics.js +3 -3
package/lines.js
CHANGED
|
@@ -5,6 +5,13 @@ class Lines {
|
|
|
5
5
|
this.rows = []
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
+
static SCREEN_WIDTH = 132
|
|
9
|
+
|
|
10
|
+
static addRemainder(widths) {
|
|
11
|
+
const sum = widths.reduce((a, b) => a + b)
|
|
12
|
+
return [...widths, Lines.SCREEN_WIDTH - sum]
|
|
13
|
+
}
|
|
14
|
+
|
|
8
15
|
addLine () {
|
|
9
16
|
this.lines.push(this.widths.map((width) => ''.padEnd(width)))
|
|
10
17
|
}
|
package/package.json
CHANGED
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
"@eslint/js": "^9.21.0",
|
|
4
4
|
"@typescript-eslint/eslint-plugin": "^4.28.4",
|
|
5
5
|
"@typescript-eslint/parser": "^4.28.4",
|
|
6
|
+
"argparse": "^2.0.1",
|
|
6
7
|
"eslint": "^7.32.0",
|
|
7
8
|
"eslint-config-standard": "^16.0.3",
|
|
8
9
|
"eslint-plugin-import": "^2.23.4",
|
|
9
10
|
"eslint-plugin-node": "^11.1.0",
|
|
10
11
|
"eslint-plugin-promise": "^5.1.0",
|
|
11
12
|
"globals": "^16.0.0",
|
|
12
|
-
"jest": "^
|
|
13
|
-
"argparse": "^2.0.1"
|
|
13
|
+
"jest": "^30.2.0"
|
|
14
14
|
},
|
|
15
15
|
"scripts": {
|
|
16
16
|
"to:debug": "node inspect node_modules/.bin/jest --runInBand -t NEO23",
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"runtime.js",
|
|
46
46
|
"src/helpers.js",
|
|
47
47
|
"src/flatten.js",
|
|
48
|
+
"src/fragment.js",
|
|
48
49
|
"src/unflatten.js",
|
|
49
50
|
"src/config.js",
|
|
50
51
|
"src/configHelpers.js",
|
|
@@ -71,6 +72,6 @@
|
|
|
71
72
|
"sort-json": "^2.0.0",
|
|
72
73
|
"uuid": "^8.3.2"
|
|
73
74
|
},
|
|
74
|
-
"version": "9.5.1-beta.
|
|
75
|
+
"version": "9.5.1-beta.7",
|
|
75
76
|
"license": "UNLICENSED"
|
|
76
77
|
}
|
package/src/config.js
CHANGED
|
@@ -10,6 +10,7 @@ const { ecatch } = require('./helpers')
|
|
|
10
10
|
const runtime = require('../runtime')
|
|
11
11
|
const _ = require('lodash')
|
|
12
12
|
const db = require('./debug')
|
|
13
|
+
const { fragmentInstantiator } = require('./fragments')
|
|
13
14
|
|
|
14
15
|
const debugBreak = () => {
|
|
15
16
|
// debugger
|
|
@@ -1107,54 +1108,21 @@ class Config {
|
|
|
1107
1108
|
return instance
|
|
1108
1109
|
}
|
|
1109
1110
|
|
|
1110
|
-
fragmentInstantiator (args, contexts) {
|
|
1111
|
-
return new Object({
|
|
1112
|
-
contexts: () => contexts,
|
|
1113
|
-
instantiate: async (mappings) => {
|
|
1114
|
-
const instantiated = _.cloneDeep(contexts)
|
|
1115
|
-
// const todo = [...instantiated]
|
|
1116
|
-
// const todo = [...instantiated]
|
|
1117
|
-
const todo = _.clone(instantiated)
|
|
1118
|
-
args = { ...args }
|
|
1119
|
-
while (todo.length > 0) {
|
|
1120
|
-
const context = todo.pop()
|
|
1121
|
-
args.context = context
|
|
1122
|
-
for (const mapping of mappings) {
|
|
1123
|
-
if (await mapping.match(args)) {
|
|
1124
|
-
await mapping.apply(args)
|
|
1125
|
-
}
|
|
1126
|
-
}
|
|
1127
|
-
for (const key of Object.keys(context)) {
|
|
1128
|
-
// if (['number', 'string', 'boolean'].includes(typeof (context[key]))) {
|
|
1129
|
-
if (!helpers.isCompound(context[key])) {
|
|
1130
|
-
continue
|
|
1131
|
-
}
|
|
1132
|
-
if (context[key].instantiated) {
|
|
1133
|
-
continue
|
|
1134
|
-
}
|
|
1135
|
-
todo.push(context[key])
|
|
1136
|
-
}
|
|
1137
|
-
}
|
|
1138
|
-
return instantiated
|
|
1139
|
-
}
|
|
1140
|
-
})
|
|
1141
|
-
}
|
|
1142
|
-
|
|
1143
1111
|
fragment (args, query) {
|
|
1144
1112
|
for (const instance of (this.instances || [])) {
|
|
1145
1113
|
for (const fragment of (instance.fragments || [])) {
|
|
1146
1114
|
if (fragment.query === query) {
|
|
1147
|
-
return
|
|
1115
|
+
return fragmentInstantiator(args, fragment.contexts)
|
|
1148
1116
|
}
|
|
1149
1117
|
}
|
|
1150
1118
|
for (const fragment of (instance.resultss || [])) {
|
|
1151
1119
|
if (fragment.isFragment && fragment.query === query) {
|
|
1152
|
-
return
|
|
1120
|
+
return fragmentInstantiator(args, fragment.contexts)
|
|
1153
1121
|
}
|
|
1154
1122
|
}
|
|
1155
1123
|
for (const fragment of (this.fragmentsBeingBuilt || [])) {
|
|
1156
1124
|
if (fragment.query === query) {
|
|
1157
|
-
return
|
|
1125
|
+
return fragmentInstantiator(args, fragment.contexts)
|
|
1158
1126
|
}
|
|
1159
1127
|
}
|
|
1160
1128
|
}
|
package/src/generators.js
CHANGED
|
@@ -202,7 +202,7 @@ class Generators {
|
|
|
202
202
|
}
|
|
203
203
|
}
|
|
204
204
|
if (!generated && generated !== '') {
|
|
205
|
-
const widths = [10, 10
|
|
205
|
+
const widths = Lines.addRemainder([10, 10])
|
|
206
206
|
const lines = new Lines(widths)
|
|
207
207
|
lines.setElement(0, 0, 'Generator')
|
|
208
208
|
const source = `${generator.km}/#${generator.index}`
|
|
@@ -230,7 +230,7 @@ class Generators {
|
|
|
230
230
|
throw { error: [message], logs: this.logs }
|
|
231
231
|
}
|
|
232
232
|
if (((config || {}).config || {}).debug) {
|
|
233
|
-
const widths = [10, 10
|
|
233
|
+
const widths = Lines.addRemainder([10, 10])
|
|
234
234
|
const lines = new Lines(widths)
|
|
235
235
|
lines.setElement(0, 0, 'Generator')
|
|
236
236
|
if (generator.index > -1 && generator.km) {
|
|
@@ -263,7 +263,7 @@ class Generators {
|
|
|
263
263
|
}
|
|
264
264
|
args.calls.pop()
|
|
265
265
|
if (!applied && ((config || {}).config || {}).debug) {
|
|
266
|
-
const widths = [10, 10
|
|
266
|
+
const widths = Lines.addRemainder([10, 10])
|
|
267
267
|
const lines = new Lines(widths)
|
|
268
268
|
lines.setElement(0, 0, 'Generator')
|
|
269
269
|
lines.setElement(0, 2, 'No generator applied')
|
package/src/helpers.js
CHANGED
|
@@ -436,6 +436,63 @@ const stableId = (tag) => {
|
|
|
436
436
|
return id
|
|
437
437
|
}
|
|
438
438
|
|
|
439
|
+
function getByPath(obj, path, defaultValue) {
|
|
440
|
+
let current = obj;
|
|
441
|
+
for (const key of path) {
|
|
442
|
+
if (current === null || current === undefined) return defaultValue;
|
|
443
|
+
if (typeof current !== 'object') return defaultValue;
|
|
444
|
+
current = current[key];
|
|
445
|
+
}
|
|
446
|
+
return current === undefined ? defaultValue : current;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* Set a value in an object by path array.
|
|
451
|
+
* Automatically creates missing objects {} or arrays [] as needed.
|
|
452
|
+
*
|
|
453
|
+
* @param {Object} obj - The root object to modify
|
|
454
|
+
* @param {Array<string|number>} path - Array of keys/indices
|
|
455
|
+
* @param {*} value - Value to set
|
|
456
|
+
* @returns {*} The set value (for chaining)
|
|
457
|
+
*/
|
|
458
|
+
function setByPath(obj, path, value) {
|
|
459
|
+
if (!Array.isArray(path) || path.length === 0) {
|
|
460
|
+
throw new Error('Path must be a non-empty array');
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
let current = obj;
|
|
464
|
+
|
|
465
|
+
for (let i = 0; i < path.length; i++) {
|
|
466
|
+
const key = path[i];
|
|
467
|
+
const isLast = i === path.length - 1;
|
|
468
|
+
|
|
469
|
+
if (isLast) {
|
|
470
|
+
// Final step — just assign
|
|
471
|
+
current[key] = value;
|
|
472
|
+
} else {
|
|
473
|
+
// Not last — ensure next level exists
|
|
474
|
+
const nextKey = path[i + 1];
|
|
475
|
+
|
|
476
|
+
if (current[key] == null) {
|
|
477
|
+
// Auto-create: array if next key is number, otherwise object
|
|
478
|
+
current[key] = typeof nextKey === 'number' || String(nextKey >>> 0) === nextKey
|
|
479
|
+
? []
|
|
480
|
+
: {};
|
|
481
|
+
} else if (Array.isArray(current[key]) && typeof nextKey !== 'number') {
|
|
482
|
+
// Safety: if current is array but next key isn't a valid index → convert to object
|
|
483
|
+
current[key] = { ...current[key] };
|
|
484
|
+
} else if (!Array.isArray(current[key]) && typeof nextKey === 'number') {
|
|
485
|
+
// If next expects array but current is object → convert
|
|
486
|
+
current[key] = Object.values(current[key]);
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
current = current[key];
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
return value;
|
|
494
|
+
}
|
|
495
|
+
|
|
439
496
|
module.exports = {
|
|
440
497
|
stableId,
|
|
441
498
|
ecatch,
|
|
@@ -463,4 +520,6 @@ module.exports = {
|
|
|
463
520
|
w,
|
|
464
521
|
suggestAssociationsFix,
|
|
465
522
|
suggestAssociationsFixFromSummaries,
|
|
523
|
+
getByPath,
|
|
524
|
+
setByPath,
|
|
466
525
|
}
|
package/src/semantics.js
CHANGED
|
@@ -218,7 +218,7 @@ class Semantics {
|
|
|
218
218
|
errorMessage = e.toString()
|
|
219
219
|
}
|
|
220
220
|
|
|
221
|
-
const widths = [10, 10
|
|
221
|
+
const widths = Lines.addRemainder([10, 10])
|
|
222
222
|
const lines = new Lines(widths)
|
|
223
223
|
lines.setElement(0, 0, 'Semantic')
|
|
224
224
|
const source = `${semantic.km}/#${semantic.index}`
|
|
@@ -248,7 +248,7 @@ class Semantics {
|
|
|
248
248
|
args.calls.touch(contextPrime)
|
|
249
249
|
// this.logs.push(`Semantics: applied ${semantic.toString()}\n to\n ${JSON.stringify(context)}\n the result was ${JSON.stringify(contextPrime)}\n`)
|
|
250
250
|
if (((config || {}).config || {}).debug) {
|
|
251
|
-
const widths = [10, 10
|
|
251
|
+
const widths = Lines.addRemainder([10, 10])
|
|
252
252
|
const lines = new Lines(widths)
|
|
253
253
|
lines.setElement(0, 0, 'Semantic')
|
|
254
254
|
if (semantic.index > -1 && semantic.km) {
|
|
@@ -295,7 +295,7 @@ class Semantics {
|
|
|
295
295
|
}
|
|
296
296
|
args.calls.pop()
|
|
297
297
|
if (!applied && ((config || {}).config || {}).debug) {
|
|
298
|
-
const widths = [10, 10
|
|
298
|
+
const widths = Lines.addRemainder([10, 10])
|
|
299
299
|
const lines = new Lines(widths)
|
|
300
300
|
lines.setElement(0, 0, 'Semantic')
|
|
301
301
|
lines.setElement(0, 2, 'No semantic applied')
|