theprogrammablemind 7.3.5-beta.24 → 7.3.5-beta.26
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 +23 -45
- package/package.json +2 -1
- package/runtime.js +11 -0
- package/src/config.js +6 -10
package/client.js
CHANGED
@@ -12,22 +12,7 @@ const { appendNoDups, InitCalls } = require('./src/helpers')
|
|
12
12
|
const sortJson = require('sort-json')
|
13
13
|
const util = require('util')
|
14
14
|
const { diffString } = require('json-diff')
|
15
|
-
|
16
|
-
const isJest = () => {
|
17
|
-
return process.env.JEST_WORKER_ID !== undefined;
|
18
|
-
}
|
19
|
-
|
20
|
-
let fs
|
21
|
-
let ArgumentParser
|
22
|
-
|
23
|
-
const setupLibs = () => {
|
24
|
-
if (!fs) {
|
25
|
-
fs = require('fs')
|
26
|
-
}
|
27
|
-
if (!ArgumentParser) {
|
28
|
-
ArgumentParser = require('argparse').ArgumentParser
|
29
|
-
}
|
30
|
-
}
|
15
|
+
const runtime = require('./runtime')
|
31
16
|
|
32
17
|
const ask = (config) => (asks) => {
|
33
18
|
for (let ask of asks) {
|
@@ -66,13 +51,13 @@ const ask = (config) => (asks) => {
|
|
66
51
|
const vimdiff = (actualJSON, expectedJSON) => {
|
67
52
|
const path = '.'
|
68
53
|
const actual = sortJson(actualJSON, { depth: 25 })
|
69
|
-
fs.writeFileSync(`${path}/actual.json`, JSON.stringify(actual, 0, 2))
|
54
|
+
runtime.fs.writeFileSync(`${path}/actual.json`, JSON.stringify(actual, 0, 2))
|
70
55
|
const expected = sortJson(expectedJSON, { depth: 25 })
|
71
|
-
fs.writeFileSync(`${path}/expected.json`, JSON.stringify(expected, 0, 2))
|
56
|
+
runtime.fs.writeFileSync(`${path}/expected.json`, JSON.stringify(expected, 0, 2))
|
72
57
|
// console.log(`vimdiff ${path}/actual.json ${path}/expected.json`)
|
73
58
|
{
|
74
|
-
const editor = process.env.EDITOR || 'vimdiff'
|
75
|
-
const child = child_process.spawn(editor, [`${path}/expected.json`, `${path}/actual.json`], { stdio: 'inherit' })
|
59
|
+
const editor = runtime.process.env.EDITOR || 'vimdiff'
|
60
|
+
const child = runtime.child_process.spawn(editor, [`${path}/expected.json`, `${path}/actual.json`], { stdio: 'inherit' })
|
76
61
|
child.on('exit', function (e, code) {
|
77
62
|
console.log('finished')
|
78
63
|
})
|
@@ -247,14 +232,13 @@ const writeTestFile = (fn, tests) => {
|
|
247
232
|
}
|
248
233
|
}
|
249
234
|
stabilize(tests)
|
250
|
-
fs.writeFileSync(fn, stringify(tests, { space: 2 }), { encoding: 'utf8', flag: 'w+' })
|
235
|
+
runtime.fs.writeFileSync(fn, stringify(tests, { space: 2 }), { encoding: 'utf8', flag: 'w+' })
|
251
236
|
}
|
252
237
|
|
253
238
|
const writeTest = (fn, query, objects, generated, paraphrases, responses, contexts, associations, metadata, config, saveDeveloper) => {
|
254
|
-
setupLibs()
|
255
239
|
let tests = []
|
256
|
-
if (fs.existsSync(fn)) {
|
257
|
-
tests = JSON.parse(fs.readFileSync(fn))
|
240
|
+
if (runtime.fs.existsSync(fn)) {
|
241
|
+
tests = JSON.parse(runtime.fs.readFileSync(fn))
|
258
242
|
}
|
259
243
|
for (let association of associations) {
|
260
244
|
association.sort()
|
@@ -720,7 +704,7 @@ const runTestsHelper = async (config, tests, failed, juicyBits) => {
|
|
720
704
|
}
|
721
705
|
|
722
706
|
const runTests = async (config, testFile, juicyBits) => {
|
723
|
-
const tests = JSON.parse(fs.readFileSync(testFile))
|
707
|
+
const tests = JSON.parse(runtime.fs.readFileSync(testFile))
|
724
708
|
const { beforeTests, afterTests } = juicyBits
|
725
709
|
beforeTests()
|
726
710
|
if (juicyBits.verbose) {
|
@@ -757,7 +741,7 @@ const saveTestsHelper = async (testFile, config, tests, todo, beforeQuery, testC
|
|
757
741
|
}
|
758
742
|
|
759
743
|
const saveTests = (config, testFile, beforeQuery, testConfig) => {
|
760
|
-
const tests = JSON.parse(fs.readFileSync(testFile))
|
744
|
+
const tests = JSON.parse(runtime.fs.readFileSync(testFile))
|
761
745
|
console.log(testFile)
|
762
746
|
return saveTestsHelper(testFile, config, tests, tests.map( (test) => test.query ), beforeQuery, testConfig)
|
763
747
|
}
|
@@ -1074,13 +1058,13 @@ const build = async ({ config, target, beforeQuery, template, errorHandler = def
|
|
1074
1058
|
return template
|
1075
1059
|
};
|
1076
1060
|
stabilizeOutput(accumulators)
|
1077
|
-
fs.writeFileSync(instanceName, JSON.stringify(Object.assign({ queries: template.queries }, accumulators), 0, 2))
|
1061
|
+
runtime.fs.writeFileSync(instanceName, JSON.stringify(Object.assign({ queries: template.queries }, accumulators), 0, 2))
|
1078
1062
|
|
1079
1063
|
// km tests file
|
1080
1064
|
const testsName = `./${target}.test.json`
|
1081
|
-
if (!fs.existsSync(testsName)) {
|
1065
|
+
if (!runtime.fs.existsSync(testsName)) {
|
1082
1066
|
console.log(`Writing km file tests file "${testsName}" since it does not exist`)
|
1083
|
-
fs.writeFileSync(testsName, JSON.stringify({}, 0, 2))
|
1067
|
+
runtime.fs.writeFileSync(testsName, JSON.stringify({}, 0, 2))
|
1084
1068
|
}
|
1085
1069
|
}
|
1086
1070
|
|
@@ -1118,10 +1102,6 @@ const knowledgeModule = async ({
|
|
1118
1102
|
const isProcess = require.main === moduleFromJSFile
|
1119
1103
|
const testConfig = test
|
1120
1104
|
|
1121
|
-
if (isProcess && isJest()) {
|
1122
|
-
setupLibs()
|
1123
|
-
}
|
1124
|
-
|
1125
1105
|
// remove test only stuff
|
1126
1106
|
if (!isProcess) {
|
1127
1107
|
config.config.operators = config.config.operators.filter( (operator) => {
|
@@ -1172,8 +1152,8 @@ const knowledgeModule = async ({
|
|
1172
1152
|
config.tests = test.contents
|
1173
1153
|
test = test.name
|
1174
1154
|
} else {
|
1175
|
-
if (fs && fs.existsSync(test)) {
|
1176
|
-
config.tests = JSON.parse(fs.readFileSync(test))
|
1155
|
+
if (runtime.fs && runtime.fs.existsSync(test)) {
|
1156
|
+
config.tests = JSON.parse(runtime.fs.readFileSync(test))
|
1177
1157
|
} else {
|
1178
1158
|
config.tests = {}
|
1179
1159
|
}
|
@@ -1190,8 +1170,7 @@ const knowledgeModule = async ({
|
|
1190
1170
|
|
1191
1171
|
if (isProcess) {
|
1192
1172
|
// setup();
|
1193
|
-
|
1194
|
-
const parser = new ArgumentParser({
|
1173
|
+
const parser = new runtime.ArgumentParser({
|
1195
1174
|
description: 'Entodicton knowledge module'
|
1196
1175
|
})
|
1197
1176
|
|
@@ -1238,7 +1217,7 @@ const knowledgeModule = async ({
|
|
1238
1217
|
}
|
1239
1218
|
|
1240
1219
|
if (args.clean) {
|
1241
|
-
const tests = JSON.parse(fs.readFileSync(testConfig.name))
|
1220
|
+
const tests = JSON.parse(runtime.fs.readFileSync(testConfig.name))
|
1242
1221
|
for (let test of tests) {
|
1243
1222
|
delete test.associations
|
1244
1223
|
}
|
@@ -1248,7 +1227,7 @@ const knowledgeModule = async ({
|
|
1248
1227
|
}
|
1249
1228
|
|
1250
1229
|
if (args.queryDelete) {
|
1251
|
-
let tests = JSON.parse(fs.readFileSync(testConfig.name))
|
1230
|
+
let tests = JSON.parse(runtime.fs.readFileSync(testConfig.name))
|
1252
1231
|
tests = tests.filter( (test) => test.query !== args.queryDelete );
|
1253
1232
|
writeTestFile(testConfig.name, tests)
|
1254
1233
|
console.log(`Remove the test for "${args.queryDelete}"`)
|
@@ -1400,7 +1379,7 @@ const knowledgeModule = async ({
|
|
1400
1379
|
const l = (n, hasError) => {
|
1401
1380
|
if (n === 0) {
|
1402
1381
|
if (hasError) {
|
1403
|
-
|
1382
|
+
processContext.exit(-1)
|
1404
1383
|
}
|
1405
1384
|
return
|
1406
1385
|
}
|
@@ -1446,7 +1425,7 @@ const knowledgeModule = async ({
|
|
1446
1425
|
l(n - 1, hasError || newError)
|
1447
1426
|
}).catch((error) => {
|
1448
1427
|
console.error(error)
|
1449
|
-
|
1428
|
+
processContext.exit(-1)
|
1450
1429
|
errorHandler(error)
|
1451
1430
|
})
|
1452
1431
|
}
|
@@ -1455,7 +1434,7 @@ const knowledgeModule = async ({
|
|
1455
1434
|
test()
|
1456
1435
|
}
|
1457
1436
|
} else if (args.loop) {
|
1458
|
-
const readline = require('readline').createInterface({ input: process.stdin, output: process.stdout })
|
1437
|
+
const readline = require('readline').createInterface({ input: runtime.process.stdin, output: runtime.process.stdout })
|
1459
1438
|
const f = () => readline.question('Enter query? (newline to quit) ', query => {
|
1460
1439
|
query = query.trim()
|
1461
1440
|
if (query.length === 0) {
|
@@ -1503,13 +1482,12 @@ const test = (name) => {
|
|
1503
1482
|
*/
|
1504
1483
|
|
1505
1484
|
const ensureTestFile = (module, name, type) => {
|
1506
|
-
setupLibs()
|
1507
1485
|
const isProcess = require.main === module
|
1508
1486
|
if (isProcess) {
|
1509
1487
|
const fn = `./${name}.${type}.json`
|
1510
|
-
if (!fs.existsSync(fn)) {
|
1488
|
+
if (!runtime.fs.existsSync(fn)) {
|
1511
1489
|
console.log('writing')
|
1512
|
-
fs.writeFileSync(fn, '[]')
|
1490
|
+
runtime.fs.writeFileSync(fn, '[]')
|
1513
1491
|
}
|
1514
1492
|
}
|
1515
1493
|
}
|
package/package.json
CHANGED
@@ -36,6 +36,7 @@
|
|
36
36
|
"lines.js",
|
37
37
|
"demo.js",
|
38
38
|
"demo.test.json",
|
39
|
+
"runtime.js",
|
39
40
|
"src/helpers.js",
|
40
41
|
"src/flatten.js",
|
41
42
|
"src/unflatten.js",
|
@@ -60,6 +61,6 @@
|
|
60
61
|
"json-stable-stringify": "^1.0.1",
|
61
62
|
"node-fetch": "^2.6.1"
|
62
63
|
},
|
63
|
-
"version": "7.3.5-beta.
|
64
|
+
"version": "7.3.5-beta.26",
|
64
65
|
"license": "ISC"
|
65
66
|
}
|
package/runtime.js
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
module.exports = {
|
2
|
+
process: {
|
3
|
+
env: "Should not be called in the browser",
|
4
|
+
exit: "Should not be called in the browser",
|
5
|
+
stdin: "Should not be called in the browser",
|
6
|
+
stdout: "Should not be called in the browser",
|
7
|
+
},
|
8
|
+
child_process: "Should not be called in the browser",
|
9
|
+
fs: "Should not be called in the browser",
|
10
|
+
ArgumentParser: "Should not be called in the browser",
|
11
|
+
}
|
package/src/config.js
CHANGED
@@ -6,6 +6,7 @@ const client = require('../client')
|
|
6
6
|
const Digraph = require('./digraph')
|
7
7
|
const helpers = require('./helpers')
|
8
8
|
const deepEqual = require('deep-equal')
|
9
|
+
const runtime = require('../runtime')
|
9
10
|
const _ = require('lodash')
|
10
11
|
|
11
12
|
const debugBreak = () => {
|
@@ -21,20 +22,18 @@ const indent = (string, indent) => {
|
|
21
22
|
return string.replace(/^/gm, ' '.repeat(indent));
|
22
23
|
}
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
global.entodictonDebugHierarchy = JSON.parse(process.env.DEBUG_HIERARCHY)
|
25
|
+
if (runtime.process.env.DEBUG_HIERARCHY) {
|
26
|
+
global.entodictonDebugHierarchy = JSON.parse(runtime.process.env.DEBUG_HIERARCHY)
|
27
27
|
}
|
28
28
|
|
29
|
-
if (process.env.DEBUG_BRIDGE) {
|
29
|
+
if (runtime.process.env.DEBUG_BRIDGE) {
|
30
30
|
// id/level
|
31
|
-
global.entodictonDebugBridge = process.env.DEBUG_BRIDGE.split('/')
|
31
|
+
global.entodictonDebugBridge = runtime.process.env.DEBUG_BRIDGE.split('/')
|
32
32
|
if (global.entodictonDebugBridge.length !== 2) {
|
33
33
|
console.log('Expected DEBUG_BRIDGE to be of the form "id/level"');
|
34
34
|
}
|
35
35
|
global.entodictonDebugBridge[1] = int(global.entodictonDebugBridge[1])
|
36
36
|
}
|
37
|
-
*/
|
38
37
|
|
39
38
|
const hierarchyCanonical = (element) => {
|
40
39
|
if (element.child && element.parent) {
|
@@ -1232,12 +1231,9 @@ class Config {
|
|
1232
1231
|
return true
|
1233
1232
|
}
|
1234
1233
|
|
1235
|
-
/*
|
1236
1234
|
dump(fn) {
|
1237
|
-
|
1238
|
-
fs.writeFileSync(fn, JSON.stringify(this.config, 0, 2))
|
1235
|
+
runtime.fs.writeFileSync(fn, JSON.stringify(this.config, 0, 2))
|
1239
1236
|
}
|
1240
|
-
*/
|
1241
1237
|
|
1242
1238
|
copy (options = {}) {
|
1243
1239
|
this.valid()
|