queueobj 14.1.4 → 15.0.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/README.md +4 -0
- package/app.js +3 -2
- package/package.json +6 -3
- package/test/package.js +6 -3
- package/tests/http_all.js +89 -0
- package/tests/json_all.js +3 -1
- package/tests/json_http_all.js +112 -0
package/README.md
CHANGED
|
@@ -28,6 +28,8 @@ Included tag appenders:
|
|
|
28
28
|
* json_name - queue and process all objects by name.
|
|
29
29
|
* json_version - queue and process all objects by version.
|
|
30
30
|
|
|
31
|
+
```
|
|
32
|
+
|
|
31
33
|
Mocha Test
|
|
32
34
|
---------
|
|
33
35
|
```
|
|
@@ -36,6 +38,7 @@ npm test
|
|
|
36
38
|
|
|
37
39
|
General Setup Test
|
|
38
40
|
---------
|
|
41
|
+
```
|
|
39
42
|
npm run test_files
|
|
40
43
|
npm run test_all
|
|
41
44
|
npm run test_top_one
|
|
@@ -62,6 +65,7 @@ npm run test_json_name_non_matching
|
|
|
62
65
|
|
|
63
66
|
Usage
|
|
64
67
|
---------
|
|
68
|
+
```
|
|
65
69
|
|
|
66
70
|
var queue = require("queueobj");
|
|
67
71
|
|
package/app.js
CHANGED
|
@@ -134,13 +134,14 @@ exports = module.exports = class QueueObj {
|
|
|
134
134
|
|
|
135
135
|
if (typeof props.appender == 'undefined')
|
|
136
136
|
t.reject('base_queue no props.appender')
|
|
137
|
-
|
|
138
137
|
if (typeof props.process_objects == 'undefined')
|
|
139
138
|
t.reject(`props.process_objects not defined`)
|
|
140
139
|
|
|
141
|
-
xlog = {appender: "console"}
|
|
140
|
+
xlog = { appender: "console" }
|
|
141
|
+
|
|
142
142
|
if (typeof props.xlog != "undefined" && typeof props.xlog.appender != "undefined")
|
|
143
143
|
xlog = props.xlog
|
|
144
|
+
|
|
144
145
|
try {
|
|
145
146
|
t.log_queue = new log_queue({
|
|
146
147
|
parent: t,
|
package/package.json
CHANGED
|
@@ -2,15 +2,16 @@
|
|
|
2
2
|
"author": {
|
|
3
3
|
"name": "Jim Manton"
|
|
4
4
|
},
|
|
5
|
-
"version": "
|
|
5
|
+
"version": "15.0.0",
|
|
6
6
|
"bundleDependencies": [],
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"base-queue": "^
|
|
8
|
+
"base-queue": "^3.0.1",
|
|
9
9
|
"chai": "^4.3.7",
|
|
10
10
|
"colors": "^1.4.0",
|
|
11
11
|
"diffler": "^2.0.4",
|
|
12
12
|
"fs": "^0.0.1-security",
|
|
13
|
-
"
|
|
13
|
+
"http": "^0.0.1-security",
|
|
14
|
+
"log-queue": "^3.0.1",
|
|
14
15
|
"mocha": "^10.2.0",
|
|
15
16
|
"typescript": "^4.9.5",
|
|
16
17
|
"valid-path": "^2.1.0"
|
|
@@ -30,6 +31,8 @@
|
|
|
30
31
|
"test_name_non_matching": "node ./tests/name_non_matching",
|
|
31
32
|
"test_version_matching": "node ./tests/version_matching",
|
|
32
33
|
"test_version_non_matching": "node ./tests/version_non_matching",
|
|
34
|
+
"test_http_all": "node ./tests/http_all",
|
|
35
|
+
"test_json_http_all": "node ./tests/json_http_all",
|
|
33
36
|
"test_json_all": "node ./tests/json_all",
|
|
34
37
|
"test_json_top_one": "node ./tests/json_top_one",
|
|
35
38
|
"test_json_bottom_one": "node ./tests/json_bottom_one",
|
package/test/package.js
CHANGED
|
@@ -6,15 +6,16 @@ const packageMock = {
|
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Jim Manton"
|
|
8
8
|
},
|
|
9
|
-
"version": "
|
|
9
|
+
"version": "15.0.0",
|
|
10
10
|
"bundleDependencies": [],
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"base-queue": "^
|
|
12
|
+
"base-queue": "^3.0.1",
|
|
13
13
|
"chai": "^4.3.7",
|
|
14
14
|
"colors": "^1.4.0",
|
|
15
15
|
"diffler": "^2.0.4",
|
|
16
16
|
"fs": "^0.0.1-security",
|
|
17
|
-
"
|
|
17
|
+
"http": "^0.0.1-security",
|
|
18
|
+
"log-queue": "^3.0.1",
|
|
18
19
|
"mocha": "^10.2.0",
|
|
19
20
|
"typescript": "^4.9.5",
|
|
20
21
|
"valid-path": "^2.1.0"
|
|
@@ -34,6 +35,8 @@ const packageMock = {
|
|
|
34
35
|
"test_name_non_matching": "node ./tests/name_non_matching",
|
|
35
36
|
"test_version_matching": "node ./tests/version_matching",
|
|
36
37
|
"test_version_non_matching": "node ./tests/version_non_matching",
|
|
38
|
+
"test_http_all": "node ./tests/http_all",
|
|
39
|
+
"test_json_http_all": "node ./tests/json_http_all",
|
|
37
40
|
"test_json_all": "node ./tests/json_all",
|
|
38
41
|
"test_json_top_one": "node ./tests/json_top_one",
|
|
39
42
|
"test_json_bottom_one": "node ./tests/json_bottom_one",
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
var queue = require("../app.js")
|
|
2
|
+
|
|
3
|
+
var tst1 = class test1 {
|
|
4
|
+
constructor(props) {
|
|
5
|
+
let t = this, fname = "test_all.test1.constructor"
|
|
6
|
+
t.log = props.log
|
|
7
|
+
t.id = props.id
|
|
8
|
+
|
|
9
|
+
t.process = t.process.bind(t)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
process(callback) {
|
|
13
|
+
let t = this, fname = "test_all.test1.process"
|
|
14
|
+
t.log({ msg: `This object (${fname}) is id (${t.id}). Do stuff here`.bgBrightGreen, type: "info" })
|
|
15
|
+
callback({ success: { msg: `processing all test1` } })
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
var tst2 = class test2 {
|
|
20
|
+
constructor(props) {
|
|
21
|
+
let t = this, fname = "test_all.test2.constructor"
|
|
22
|
+
t.log = props.log
|
|
23
|
+
t.id = props.id
|
|
24
|
+
|
|
25
|
+
t.process = t.process.bind(t)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
process(callback) {
|
|
29
|
+
let t = this, fname = "test_all.test2.process"
|
|
30
|
+
t.log({ msg: `This object (${fname}) is id (${t.id}). Do stuff here`.bgBrightGreen, type: "info" })
|
|
31
|
+
setTimeout(() => {
|
|
32
|
+
callback({ success: { msg: `processing all test2` } })
|
|
33
|
+
}, 4000)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
var tst3 = class test3 {
|
|
38
|
+
constructor(props) {
|
|
39
|
+
let t = this, fname = "test_all.test3.constructor"
|
|
40
|
+
t.log = props.log
|
|
41
|
+
t.id = props.id
|
|
42
|
+
|
|
43
|
+
t.process = t.process.bind(t)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
process(callback) {
|
|
47
|
+
let t = this, fname = "test_all.test3.process"
|
|
48
|
+
t.log({ msg: `This object (${fname}) is id (${t.id}). Do stuff here`.bgBrightGreen, type: "info" })
|
|
49
|
+
// callback({success: { msg: `processing all test3` }})
|
|
50
|
+
callback({ error: { msg: `there is some problem thrown here on test3` } })
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
var tst4 = class test4 {
|
|
55
|
+
constructor(props) {
|
|
56
|
+
let t = this, fname = "test_all.test4.constructor"
|
|
57
|
+
t.log = props.log
|
|
58
|
+
t.id = props.id
|
|
59
|
+
|
|
60
|
+
t.process = t.process.bind(t)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
process(callback) {
|
|
64
|
+
let t = this, fname = "test_all.test4.process"
|
|
65
|
+
t.log({ msg: `This object (${fname}) is id (${t.id}). Do stuff here`.bgBrightGreen, type: "info" })
|
|
66
|
+
callback({ success: { msg: `processing all test4` } })
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
var qObj = new queue()
|
|
71
|
+
|
|
72
|
+
qObj.init().process({
|
|
73
|
+
appender: "all",
|
|
74
|
+
xlog: {appender: "http", hostname: "127.0.0.1", port: 3003},
|
|
75
|
+
exclude_logMsg: ["debug"], /* example ["debug", "info"] */
|
|
76
|
+
process_objects: [tst1, tst2, tst3, tst4]
|
|
77
|
+
}).then((success) => {
|
|
78
|
+
qObj.logMsg({ msg: `test success: {msg: "all objects processed with no errors"}`.success.italic.bold, type: "success" })
|
|
79
|
+
qObj.log_queue.server()
|
|
80
|
+
}, (error) => {
|
|
81
|
+
if (typeof error == "string") {
|
|
82
|
+
qObj.logMsg({ msg: `error: ${error}`.error.italic.bold, type: "error" })
|
|
83
|
+
} else {
|
|
84
|
+
let add_s = (error.error_count > 1) ? 's' : ''
|
|
85
|
+
qObj.logMsg({ msg: `${error.error_count} error${add_s} detected`.error.italic.bold, type: "error" })
|
|
86
|
+
}
|
|
87
|
+
qObj.log_queue.server()
|
|
88
|
+
})
|
|
89
|
+
|
package/tests/json_all.js
CHANGED
|
@@ -17,6 +17,7 @@ var file_object = class file_obj {
|
|
|
17
17
|
constructor(props) {
|
|
18
18
|
let t = this, fname = "file_obj.constructor"
|
|
19
19
|
try {
|
|
20
|
+
|
|
20
21
|
t.id = props.id
|
|
21
22
|
t.log = props.log
|
|
22
23
|
t.name = props.name
|
|
@@ -26,6 +27,7 @@ var file_object = class file_obj {
|
|
|
26
27
|
t.errors = false
|
|
27
28
|
t.error_msg = 'none'
|
|
28
29
|
|
|
30
|
+
|
|
29
31
|
// if (t.id == 104) {
|
|
30
32
|
// t.errors = true
|
|
31
33
|
// t.error_msg = `some sort of error here`
|
|
@@ -97,7 +99,7 @@ qRequire.init().process({
|
|
|
97
99
|
qRequire.logMsg({ msg: `test success: json_all objects processed with no errors`.success.italic.bold, type: "success" })
|
|
98
100
|
}, (error) => {
|
|
99
101
|
if (typeof error == "string") {
|
|
100
|
-
qRequire.logMsg({msg: `error: ${error}`.error.italic.bold, type: "error"})
|
|
102
|
+
qRequire.logMsg({ msg: `error: ${error}`.error.italic.bold, type: "error" })
|
|
101
103
|
|
|
102
104
|
} else {
|
|
103
105
|
let add_s = (error.error_count > 1) ? 's' : ''
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
var file_queue = require("../app.js"),
|
|
2
|
+
fs = require('fs'),
|
|
3
|
+
validPath = require('valid-path')
|
|
4
|
+
|
|
5
|
+
var file_data = [
|
|
6
|
+
{ props: { id: 100, name: "all", absolute_path: __filename, check: true } },
|
|
7
|
+
{ props: { id: 101, name: "func_all", absolute_path: __filename, check: true } },
|
|
8
|
+
{ props: { id: 102, name: "top_one", absolute_path: __filename, check: true } },
|
|
9
|
+
{ props: { id: 103, name: "bottom_one", absolute_path: __filename, check: true } },
|
|
10
|
+
{ props: { id: 104, name: "sync_all", absolute_path: __filename, check: true } },
|
|
11
|
+
{ props: { id: 105, name: "status", absolute_path: __filename, check: true } },
|
|
12
|
+
{ props: { id: 106, name: "name", absolute_path: __filename, check: true } },
|
|
13
|
+
{ props: { id: 107, name: "version", absolute_path: __filename, check: true } }
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
var file_object = class file_obj {
|
|
17
|
+
constructor(props) {
|
|
18
|
+
let t = this, fname = "file_obj.constructor"
|
|
19
|
+
try {
|
|
20
|
+
|
|
21
|
+
t.id = props.id
|
|
22
|
+
t.log = props.log
|
|
23
|
+
t.name = props.name
|
|
24
|
+
t.path = props.relative_path
|
|
25
|
+
t.absolute_path = props.absolute_path
|
|
26
|
+
t.status = 'init'
|
|
27
|
+
t.errors = false
|
|
28
|
+
t.error_msg = 'none'
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
// if (t.id == 104) {
|
|
32
|
+
// t.errors = true
|
|
33
|
+
// t.error_msg = `some sort of error here`
|
|
34
|
+
// }
|
|
35
|
+
|
|
36
|
+
t.process = t.process.bind(t)
|
|
37
|
+
t.do_checks = t.do_checks.bind(t)
|
|
38
|
+
|
|
39
|
+
if (props.check) {
|
|
40
|
+
t.do_checks()
|
|
41
|
+
}
|
|
42
|
+
} catch (e) {
|
|
43
|
+
e.message = `${fname} error: ${e.message}`
|
|
44
|
+
throw e
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return t
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
do_checks() {
|
|
51
|
+
let t = this, path_to_check,
|
|
52
|
+
last_item = t.absolute_path.split("\\").pop(),
|
|
53
|
+
check_file = t.absolute_path.split(last_item)[0], check_path = t.path.split('/')
|
|
54
|
+
|
|
55
|
+
check_file = check_file.replace(/\\/g, "/");
|
|
56
|
+
path_to_check = validPath(t.path);
|
|
57
|
+
|
|
58
|
+
if (!path_to_check.valid) {
|
|
59
|
+
t.errors = true
|
|
60
|
+
t.error_msg = `id = ${t.id} name(${t.name}) Error in ${path_to_check.data.input}: ${path_to_check.error})`
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
check_path.map((dat, i) => {
|
|
64
|
+
if (/^[a-zA-Z._]+$/.test(dat)) {
|
|
65
|
+
if (dat != '.')
|
|
66
|
+
check_file += dat + '/'
|
|
67
|
+
}
|
|
68
|
+
})
|
|
69
|
+
check_file = check_file.slice(0, -1)
|
|
70
|
+
try {
|
|
71
|
+
if (!fs.existsSync(check_file)) {
|
|
72
|
+
t.errors = true
|
|
73
|
+
t.error_msg = `id = ${t.id} name(${t.name}) file (${check_file} does not exist)`
|
|
74
|
+
}
|
|
75
|
+
} catch (e) {
|
|
76
|
+
e.message = "file_obj do_checks error: " + e.message
|
|
77
|
+
throw (e)
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
process(callback) {
|
|
82
|
+
let t = this
|
|
83
|
+
t.log({ msg: `processing object id ${t.id}. Do a bunch of stuff here.`.silly, type: "silly" })
|
|
84
|
+
if (t.errors)
|
|
85
|
+
callback({ error: { msg: t.error_msg } })
|
|
86
|
+
else
|
|
87
|
+
callback({ success: { msg: `id = ${t.id} name(${t.name})` } })
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
var qRequire = new file_queue()
|
|
92
|
+
|
|
93
|
+
qRequire.init().process({
|
|
94
|
+
appender: "json_all",
|
|
95
|
+
xlog: {appender: "http", hostname: "127.0.0.1", port: 3002},
|
|
96
|
+
exclude_logMsg: ["debug"], /* default ["debug", "silly", "info"] */
|
|
97
|
+
process_objects: [file_object],
|
|
98
|
+
data_to_process_array: file_data
|
|
99
|
+
}).then((success) => {
|
|
100
|
+
qRequire.logMsg({ msg: `test success: json_all objects processed with no errors`.success.italic.bold, type: "success" })
|
|
101
|
+
qRequire.log_queue.server()
|
|
102
|
+
}, (error) => {
|
|
103
|
+
if (typeof error == "string") {
|
|
104
|
+
qRequire.logMsg({ msg: `error: ${error}`.error.italic.bold, type: "error" })
|
|
105
|
+
|
|
106
|
+
} else {
|
|
107
|
+
let add_s = (error.error_count > 1) ? 's' : ''
|
|
108
|
+
qRequire.logMsg({ msg: `${error.error_count} error${add_s} detected`.error.italic.bold, type: "error" })
|
|
109
|
+
}
|
|
110
|
+
qRequire.log_queue.server()
|
|
111
|
+
})
|
|
112
|
+
|