theprogrammablemind 7.3.9 → 7.3.10-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/package.json +2 -2
- package/src/config.js +53 -20
- package/src/generators.js +6 -6
package/package.json
CHANGED
@@ -15,7 +15,7 @@
|
|
15
15
|
"tod": "node inspect node_modules/.bin/jest --runInBand -t ONE23",
|
16
16
|
"lint:fix": "eslint \"**/*.js\" --fix",
|
17
17
|
"lint": "eslint \"**/*.js\"",
|
18
|
-
"to": "node node_modules/.bin/jest --runInBand -t
|
18
|
+
"to": "node node_modules/.bin/jest --runInBand -t ONE23",
|
19
19
|
"test": "jest --config ./jest.config.json",
|
20
20
|
"test:watch": "npm run test -- --watch"
|
21
21
|
},
|
@@ -61,6 +61,6 @@
|
|
61
61
|
"json-stable-stringify": "^1.0.1",
|
62
62
|
"node-fetch": "^2.6.1"
|
63
63
|
},
|
64
|
-
"version": "7.3.
|
64
|
+
"version": "7.3.10-beta.0",
|
65
65
|
"license": "ISC"
|
66
66
|
}
|
package/src/config.js
CHANGED
@@ -172,7 +172,7 @@ class KM {
|
|
172
172
|
return this.toNS(this._name)
|
173
173
|
}
|
174
174
|
|
175
|
-
constructor ({ config, namespace = [], uuid, isSelf = false }) {
|
175
|
+
constructor ({ config, getCounter, namespace = [], uuid, isSelf = false }) {
|
176
176
|
if (uuid) {
|
177
177
|
this._uuid = uuid
|
178
178
|
this._class = 'KM'
|
@@ -226,6 +226,7 @@ class KM {
|
|
226
226
|
const config = configDup(this._config, options)
|
227
227
|
const km = new KM({
|
228
228
|
config,
|
229
|
+
getCounter: options.getCounter,
|
229
230
|
name: this._name,
|
230
231
|
_uuid: config._uuid,
|
231
232
|
namespace: this._namespace,
|
@@ -239,7 +240,8 @@ class KM {
|
|
239
240
|
name: this._name,
|
240
241
|
config: configDup(this._config),
|
241
242
|
// _uuid: uuidv4(),
|
242
|
-
_uuid: getCounter(this._config._name),
|
243
|
+
_uuid: this._config.getCounter(this._config._name),
|
244
|
+
getCounter: (name) => this._config.getCounter(name),
|
243
245
|
namespace: this._namespace,
|
244
246
|
isSelf: this._isSelf
|
245
247
|
})
|
@@ -319,15 +321,15 @@ const multiApiImpl = (initializer) => {
|
|
319
321
|
})
|
320
322
|
}
|
321
323
|
|
322
|
-
let configCounter = 1
|
323
|
-
|
324
|
-
const getCounter = (maybeName = '') => {
|
325
|
-
const counter = configCounter
|
326
|
-
configCounter += 1
|
327
|
-
return `${maybeName}${counter}`
|
328
|
-
}
|
329
324
|
|
330
325
|
class Config {
|
326
|
+
|
327
|
+
getCounter (maybeName = '') {
|
328
|
+
const counter = this.configCounter
|
329
|
+
this.configCounter += 1
|
330
|
+
return `${maybeName}${counter}`
|
331
|
+
}
|
332
|
+
|
331
333
|
defaultConfig () {
|
332
334
|
this.config = {
|
333
335
|
operators: [], // TODO
|
@@ -363,6 +365,7 @@ class Config {
|
|
363
365
|
for (const bag of bags) {
|
364
366
|
this.config[bag] = []
|
365
367
|
}
|
368
|
+
this.configCounter = 1
|
366
369
|
// this.wasInitialized = false
|
367
370
|
}
|
368
371
|
|
@@ -989,7 +992,7 @@ class Config {
|
|
989
992
|
this._namespace = []
|
990
993
|
this._eqClasses = []
|
991
994
|
// this._uuid = uuidv4()
|
992
|
-
this._uuid = getCounter(this.name)
|
995
|
+
this._uuid = this.getCounter(this.name)
|
993
996
|
if (config) {
|
994
997
|
config = _.cloneDeep(config)
|
995
998
|
this.config = config
|
@@ -1083,7 +1086,7 @@ class Config {
|
|
1083
1086
|
}
|
1084
1087
|
}
|
1085
1088
|
this.initConfig = _.cloneDeep(this.config)
|
1086
|
-
this.configs.push(new KM({ config: this.config, uuid: this._uuid }))
|
1089
|
+
this.configs.push(new KM({ config: this.config, getCounter: (name) => this.config.getCounter(name), uuid: this._uuid }))
|
1087
1090
|
|
1088
1091
|
/*
|
1089
1092
|
if (config) {
|
@@ -1166,7 +1169,7 @@ class Config {
|
|
1166
1169
|
set uuid (uuid) {
|
1167
1170
|
const map = { [this._uuid]: uuid }
|
1168
1171
|
this._uuid = uuid
|
1169
|
-
configCounter += 1
|
1172
|
+
this.configCounter += 1
|
1170
1173
|
this.mapUUIDs(map)
|
1171
1174
|
}
|
1172
1175
|
|
@@ -1235,12 +1238,12 @@ class Config {
|
|
1235
1238
|
runtime.fs.writeFileSync(fn, JSON.stringify(this.config, 0, 2))
|
1236
1239
|
}
|
1237
1240
|
|
1238
|
-
copy (options = {}) {
|
1241
|
+
copy (options = { callInitializers: true }) {
|
1239
1242
|
this.valid()
|
1240
1243
|
const cp = new Config()
|
1241
1244
|
cp.logs = []
|
1242
1245
|
cp.transitoryMode = this.transitoryMode
|
1243
|
-
cp.configs = this.configs.map((km) => km.copy2(Object.assign({}, options, { callInitializers: false })))
|
1246
|
+
cp.configs = this.configs.map((km) => km.copy2(Object.assign({}, options, { getCounter: (name) => cp.getCounter(name), callInitializers: false })))
|
1244
1247
|
cp._uuid = cp.configs[0]._uuid
|
1245
1248
|
cp.initializerFn = this.initializerFn
|
1246
1249
|
cp.initAfterApi = this.initAfterApi
|
@@ -1254,6 +1257,7 @@ class Config {
|
|
1254
1257
|
cp.isModule = this.isModule
|
1255
1258
|
cp.initInstances = this.initInstances.slice()
|
1256
1259
|
cp.instances = this.instances.slice()
|
1260
|
+
cp.configCounter = this.configCounter
|
1257
1261
|
|
1258
1262
|
cp.initConfig = _.cloneDeep(this.initConfig)
|
1259
1263
|
cp.defaultConfig()
|
@@ -1264,6 +1268,7 @@ class Config {
|
|
1264
1268
|
Object.assign(cp.config.objects, _.cloneDeep(this.initConfig.objects || {}))
|
1265
1269
|
}
|
1266
1270
|
// cp.initializeConfigFromConfigs({ others: [], objects: cp.config.objects.namespaced, moreNames: [], ...options })
|
1271
|
+
// cp.initializeConfigFromConfigs(Object.assign({ others: [], objects: cp.config.objects.namespaced, moreNames: [] }, { callInitializers: false }))
|
1267
1272
|
cp.initializeConfigFromConfigs(Object.assign({ others: [], objects: cp.config.objects.namespaced, moreNames: [] }, options))
|
1268
1273
|
const map = {}
|
1269
1274
|
for (let i = 0; i < this.configs.length; ++i) {
|
@@ -1271,6 +1276,9 @@ class Config {
|
|
1271
1276
|
}
|
1272
1277
|
cp.mapUUIDs(map)
|
1273
1278
|
|
1279
|
+
if (options.callInitializers) {
|
1280
|
+
cp.rebuild(options)
|
1281
|
+
}
|
1274
1282
|
if (cp._api) {
|
1275
1283
|
cp._api.objects = cp.config.objects
|
1276
1284
|
cp._api.config = () => (cp instanceof Config) ? cp : cp.config
|
@@ -1287,9 +1295,6 @@ class Config {
|
|
1287
1295
|
cp.config.objects.namespaced[km._uuid] = {}
|
1288
1296
|
})
|
1289
1297
|
|
1290
|
-
if (options.callInitializers) {
|
1291
|
-
cp.rebuild(options)
|
1292
|
-
}
|
1293
1298
|
cp.valid()
|
1294
1299
|
return cp
|
1295
1300
|
}
|
@@ -1421,7 +1426,16 @@ class Config {
|
|
1421
1426
|
}
|
1422
1427
|
}
|
1423
1428
|
|
1424
|
-
initializer (fn,
|
1429
|
+
initializer (fn, options = {}) {
|
1430
|
+
if (options) {
|
1431
|
+
for (let option of Object.keys(options)) {
|
1432
|
+
const validOptions = ['initAfterApi']
|
1433
|
+
if (!['initAfterApi'].includes(option)) {
|
1434
|
+
throw `For Config.initializer, unrecognized option ${option}. The valid options are ${validOptions}`
|
1435
|
+
}
|
1436
|
+
}
|
1437
|
+
}
|
1438
|
+
const { initAfterApi = false } = options;
|
1425
1439
|
this.wasInitialized = false
|
1426
1440
|
this.initAfterApi = initAfterApi
|
1427
1441
|
this.initializerFn = (args) => {
|
@@ -1767,7 +1781,7 @@ class Config {
|
|
1767
1781
|
// initialize the configs in context
|
1768
1782
|
|
1769
1783
|
if (callInitializers) {
|
1770
|
-
this.configs.forEach(({ namespace, uuid, config, isSelf }) => {
|
1784
|
+
[...this.configs].reverse().forEach(({ namespace, uuid, config, isSelf }) => {
|
1771
1785
|
if (isSelf) {
|
1772
1786
|
config = this
|
1773
1787
|
}
|
@@ -1935,6 +1949,25 @@ class Config {
|
|
1935
1949
|
if (!this.config.hasOwnProperty(property)) {
|
1936
1950
|
throw `Setting invalid property ${property}`
|
1937
1951
|
}
|
1952
|
+
|
1953
|
+
if ('words' == property) {
|
1954
|
+
for (let word in value) {
|
1955
|
+
for (let def of value[word]) {
|
1956
|
+
if (!def['uuid']) {
|
1957
|
+
throw `All definitions for '${property}' must have the uuid property set (config.uuid). uuid is missing from ${JSON.stringify(def)} for the word '${word}'`
|
1958
|
+
}
|
1959
|
+
}
|
1960
|
+
}
|
1961
|
+
}
|
1962
|
+
|
1963
|
+
if (['operators', 'bridges'].includes(property)) {
|
1964
|
+
for (let def of value) {
|
1965
|
+
if (!def['uuid']) {
|
1966
|
+
throw `All definitions for '${property}' must have the uuid property set (config.uuid). uuid is missing from ${JSON.stringify(def)}`
|
1967
|
+
}
|
1968
|
+
}
|
1969
|
+
}
|
1970
|
+
|
1938
1971
|
this.config[property] = value
|
1939
1972
|
// this.configs[0][property] = value
|
1940
1973
|
}
|
@@ -1982,7 +2015,7 @@ class Config {
|
|
1982
2015
|
// this.configs = this.configs.concat(new KM({config: more}));
|
1983
2016
|
// only set for the first one the rest have it set
|
1984
2017
|
const namespace = this._namespace.concat(more._namespace)
|
1985
|
-
const moreKMs1 = [new KM({ config: more, uuid: more.uuid, namespace })]
|
2018
|
+
const moreKMs1 = [new KM({ config: more, getCounter: (name) => this.getCounter(name), uuid: more.uuid, namespace })]
|
1986
2019
|
const moreKMs2 = more.configs.slice(1).map((km) => {
|
1987
2020
|
return km
|
1988
2021
|
// const cp = km.copy()
|
package/src/generators.js
CHANGED
@@ -171,7 +171,7 @@ class Generators {
|
|
171
171
|
let context = contexts[icontext]
|
172
172
|
context = Object.assign({}, context, assumed)
|
173
173
|
// let context_prime = JSON.stringify(context);
|
174
|
-
let
|
174
|
+
let generated = context
|
175
175
|
let applied = false
|
176
176
|
const stack = args.calls.push()
|
177
177
|
for (let igenerator = 0; igenerator < this.generators.length; ++igenerator) {
|
@@ -189,10 +189,10 @@ class Generators {
|
|
189
189
|
// this.logs.push(`Generators: applied ${generator.toString()}\n to\n ${JSON.stringify(context)}`)
|
190
190
|
let errorMessage = 'The apply function did not return a value'
|
191
191
|
try {
|
192
|
-
|
192
|
+
generated= generator.apply(args, objects, g, args.gs, context, hierarchy, config, response, log)
|
193
193
|
} catch( e ) {
|
194
194
|
// the next if handle this
|
195
|
-
|
195
|
+
generated = null
|
196
196
|
if (e.stack && e.message) {
|
197
197
|
errorMessage = `Error applying generator '${generator.notes}'. Error is ${e.toString()} stack is ${e.stack}. Generator is ${generator.toString()}`
|
198
198
|
} else if (e.error) {
|
@@ -201,7 +201,7 @@ class Generators {
|
|
201
201
|
errorMessage = e.toString()
|
202
202
|
}
|
203
203
|
}
|
204
|
-
if (!
|
204
|
+
if (!generated && generated !== '') {
|
205
205
|
const widths = [10, 10, 90]
|
206
206
|
const lines = new Lines(widths)
|
207
207
|
lines.setElement(0, 0, 'Generator')
|
@@ -244,7 +244,7 @@ class Generators {
|
|
244
244
|
lines.setElement(0, 2, generator.toString())
|
245
245
|
lines.newRow()
|
246
246
|
lines.setElement(0, 1, 'RESULT')
|
247
|
-
lines.setElement(0, 2,
|
247
|
+
lines.setElement(0, 2, generated)
|
248
248
|
lines.newRow()
|
249
249
|
lines.setElement(0, 1, 'STACK')
|
250
250
|
lines.setElement(0, 2, stack)
|
@@ -275,7 +275,7 @@ class Generators {
|
|
275
275
|
lines.setElement(0, 2, JSON.stringify(context, null, 2))
|
276
276
|
this.logs.push(lines.toString())
|
277
277
|
}
|
278
|
-
contextsPrime.push(
|
278
|
+
contextsPrime.push(generated)
|
279
279
|
}
|
280
280
|
return contextsPrime
|
281
281
|
}
|