file-obj-queue 2.0.5 → 3.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.
Files changed (50) hide show
  1. package/.github/workflows/{github-actions-demo.yml → github-actions.yml} +1 -1
  2. package/.github/workflows/node.js.yml +1 -0
  3. package/LICENSE +1 -1
  4. package/README.md +132 -7
  5. package/app.js +155 -40
  6. package/lib/appenders/all.js +17 -0
  7. package/lib/appenders/base.js +189 -0
  8. package/lib/appenders/bottom_one.js +17 -0
  9. package/lib/appenders/func_all.js +17 -0
  10. package/lib/appenders/name.js +17 -0
  11. package/lib/appenders/status.js +17 -0
  12. package/lib/appenders/sync.js +17 -0
  13. package/lib/appenders/sync_all.js +17 -0
  14. package/lib/appenders/top_one.js +17 -0
  15. package/lib/appenders/version.js +17 -0
  16. package/package.json +24 -3
  17. package/test/app.js +5 -1
  18. package/test/package.js +25 -3
  19. package/tests/all.js +85 -0
  20. package/tests/appenders/all.js +1 -1
  21. package/tests/appenders/base.js +1 -1
  22. package/tests/appenders/bottom_one.js +1 -1
  23. package/tests/appenders/func_all.js +1 -1
  24. package/tests/appenders/sync.js +1 -1
  25. package/tests/appenders/sync_all.js +1 -1
  26. package/tests/appenders/top_one.js +1 -1
  27. package/tests/appenders/version.js +1 -1
  28. package/tests/bottom_one.js +86 -0
  29. package/tests/files.js +50 -32
  30. package/tests/func_all.js +94 -0
  31. package/tests/json_all.js +107 -0
  32. package/tests/json_bottom_one.js +108 -0
  33. package/tests/json_func_all.js +109 -0
  34. package/tests/json_name_matching.js +109 -0
  35. package/tests/json_name_non_matching.js +109 -0
  36. package/tests/json_status_matching.js +110 -0
  37. package/tests/json_status_non_matching.js +110 -0
  38. package/tests/json_top_one.js +108 -0
  39. package/tests/json_version_matching.js +110 -0
  40. package/tests/json_version_non_matching.js +110 -0
  41. package/tests/name_matching.js +90 -0
  42. package/tests/name_non_matching.js +90 -0
  43. package/tests/status_matching.js +90 -0
  44. package/tests/status_non_matching.js +90 -0
  45. package/tests/top_one.js +85 -0
  46. package/tests/version_matching.js +90 -0
  47. package/tests/version_non_matching.js +90 -0
  48. package/base_queue/app.js +0 -146
  49. package/base_queue/appenders/base.js +0 -77
  50. package/base_queue/appenders/json_all.js +0 -70
@@ -0,0 +1,107 @@
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
+ t.id = props.id
21
+ t.log = props.log
22
+ t.name = props.name
23
+ t.path = props.relative_path
24
+ t.absolute_path = props.absolute_path
25
+ t.status = 'init'
26
+ t.errors = false
27
+ t.error_msg = 'none'
28
+
29
+ // if (t.id == 104) {
30
+ // t.errors = true
31
+ // t.error_msg = `some sort of error here`
32
+ // }
33
+
34
+ t.process = t.process.bind(t)
35
+ t.do_checks = t.do_checks.bind(t)
36
+
37
+ if (props.check) {
38
+ t.do_checks()
39
+ }
40
+ } catch (e) {
41
+ e.message = `${fname} error: ${e.message}`
42
+ throw e
43
+ }
44
+
45
+ return t
46
+ }
47
+
48
+ do_checks() {
49
+ let t = this, path_to_check,
50
+ last_item = t.absolute_path.split("\\").pop(),
51
+ check_file = t.absolute_path.split(last_item)[0], check_path = t.path.split('/')
52
+
53
+ check_file = check_file.replace(/\\/g, "/");
54
+ path_to_check = validPath(t.path);
55
+
56
+ if (!path_to_check.valid) {
57
+ t.errors = true
58
+ t.error_msg = `id = ${t.id} name(${t.name}) Error in ${path_to_check.data.input}: ${path_to_check.error})`
59
+ }
60
+
61
+ check_path.map((dat, i) => {
62
+ if (/^[a-zA-Z._]+$/.test(dat)) {
63
+ if (dat != '.')
64
+ check_file += dat + '/'
65
+ }
66
+ })
67
+ check_file = check_file.slice(0, -1)
68
+ try {
69
+ if (!fs.existsSync(check_file)) {
70
+ t.errors = true
71
+ t.error_msg = `id = ${t.id} name(${t.name}) file (${check_file} does not exist)`
72
+ }
73
+ } catch (e) {
74
+ e.message = "file_obj do_checks error: " + e.message
75
+ throw (e)
76
+ }
77
+ }
78
+
79
+ process(callback) {
80
+ let t = this
81
+ t.log({ msg: `processing object id ${t.id}. Do a bunch of stuff here.`.silly, type: "silly" })
82
+ if (t.errors)
83
+ callback({ error: { msg: t.error_msg } })
84
+ else
85
+ callback({ success: { msg: `id = ${t.id} name(${t.name})` } })
86
+ }
87
+ }
88
+
89
+ var qRequire = new file_queue()
90
+
91
+ qRequire.init().process({
92
+ appender: "json_all",
93
+ exclude_logMsg: ["debug", "silly", "info"], /* default [] */
94
+ process_objects: [file_object],
95
+ data_to_process_array: file_data
96
+ }).then((success) => {
97
+ qRequire.logMsg({ msg: `test success: json_all objects processed with no errors`.success.italic.bold, type: "success" })
98
+ }, (error) => {
99
+ if (typeof error == "string") {
100
+ qRequire.logMsg({msg: `error: ${error}`.error.italic.bold, type: "error"})
101
+
102
+ } else {
103
+ let add_s = (error.error_count > 1) ? 's' : ''
104
+ qRequire.logMsg({ msg: `${error.error_count} error${add_s} detected`.error.italic.bold, type: "error" })
105
+ }
106
+ })
107
+
@@ -0,0 +1,108 @@
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
+ t.id = props.id
21
+ t.log = props.log
22
+ t.name = props.name
23
+ t.path = props.relative_path
24
+ t.absolute_path = props.absolute_path
25
+ t.status = 'init'
26
+ t.errors = false
27
+ t.error_msg = 'none'
28
+
29
+ // if (t.id == 104) {
30
+ // t.errors = true
31
+ // t.error_msg = `some sort of error here`
32
+ // }
33
+ // }
34
+
35
+ t.process = t.process.bind(t)
36
+ t.do_checks = t.do_checks.bind(t)
37
+
38
+ if (props.check) {
39
+ t.do_checks()
40
+ }
41
+ } catch (e) {
42
+ e.message = `${fname} error: ${e.message}`
43
+ throw e
44
+ }
45
+
46
+ return t
47
+ }
48
+
49
+ do_checks() {
50
+ let t = this, path_to_check,
51
+ last_item = t.absolute_path.split("\\").pop(),
52
+ check_file = t.absolute_path.split(last_item)[0], check_path = t.path.split('/')
53
+
54
+ check_file = check_file.replace(/\\/g, "/");
55
+ path_to_check = validPath(t.path);
56
+
57
+ if (!path_to_check.valid) {
58
+ t.errors = true
59
+ t.error_msg = `id = ${t.id} name(${t.name}) Error in ${path_to_check.data.input}: ${path_to_check.error})`
60
+ }
61
+
62
+ check_path.map((dat, i) => {
63
+ if (/^[a-zA-Z._]+$/.test(dat)) {
64
+ if (dat != '.')
65
+ check_file += dat + '/'
66
+ }
67
+ })
68
+ check_file = check_file.slice(0, -1)
69
+ try {
70
+ if (!fs.existsSync(check_file)) {
71
+ t.errors = true
72
+ t.error_msg = `id = ${t.id} name(${t.name}) file (${check_file} does not exist)`
73
+ }
74
+ } catch (e) {
75
+ e.message = "file_obj do_checks error: " + e.message
76
+ throw (e)
77
+ }
78
+ }
79
+
80
+ process(callback) {
81
+ let t = this
82
+ t.log({ msg: `processing object id ${t.id} name: ${t.name}. Do a bunch of stuff here.`.silly, type: "silly" })
83
+ if (t.errors)
84
+ callback({ error: { msg: t.error_msg } })
85
+ else
86
+ callback({ success: { msg: `id: ${t.id} name: ${t.name}` } })
87
+ }
88
+ }
89
+
90
+ var qRequire = new file_queue()
91
+
92
+ qRequire.init().process({
93
+ appender: "json_bottom_one",
94
+ exclude_logMsg: ["debug", "silly", "info"], /* default [] */
95
+ process_objects: [file_object],
96
+ data_to_process_array: file_data
97
+ }).then((success) => {
98
+ qRequire.logMsg({ msg: `test success: bottom_one file objects processed with no errors`.success.italic.bold, type: "success" })
99
+ }, (error) => {
100
+ if (typeof error == "string") {
101
+ qRequire.logMsg({msg: `error: ${error}`.error.italic.bold, type: "error"})
102
+
103
+ } else {
104
+ let add_s = (error.error_count > 1) ? 's' : ''
105
+ qRequire.logMsg({ msg: `${error.error_count} error${add_s} detected`.error.italic.bold, type: "error" })
106
+ }
107
+ })
108
+
@@ -0,0 +1,109 @@
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
+ t.id = props.id
21
+ t.log = props.log
22
+ t.name = props.name
23
+ t.path = props.relative_path
24
+ t.absolute_path = props.absolute_path
25
+ t.status = 'init'
26
+ t.errors = false
27
+ t.error_msg = 'none'
28
+
29
+ // if (t.id == 104) {
30
+ // t.errors = true
31
+ // t.error_msg = `some sort of error here`
32
+ // }
33
+ t.base_queue_process_function = t.a_cool_function
34
+
35
+ t.do_checks = t.do_checks.bind(t)
36
+ t.a_cool_function = t.a_cool_function.bind(t)
37
+ t.base_queue_process_function = t.base_queue_process_function.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
+ a_cool_function(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_func_all",
95
+ exclude_logMsg: ["debug", "silly", "info"], /* default [] */
96
+ process_objects: [file_object],
97
+ data_to_process_array: file_data
98
+ }).then((success) => {
99
+ qRequire.logMsg({ msg: `test success: json_func_all objects processed with no errors`.success.italic.bold, type: "success" })
100
+ }, (error) => {
101
+ if (typeof error == "string") {
102
+ qRequire.logMsg({ msg: `error: ${error}`.error.italic.bold, type: "error" })
103
+
104
+ } else {
105
+ let add_s = (error.error_count > 1) ? 's' : ''
106
+ qRequire.logMsg({ msg: `${error.error_count} error${add_s} detected`.error.italic.bold, type: "error" })
107
+ }
108
+ })
109
+
@@ -0,0 +1,109 @@
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", status: "new", absolute_path: __filename, check: true } },
7
+ { props: { id: 101, name: "func_all", status: "done", absolute_path: __filename, check: true } },
8
+ { props: { id: 102, name: "top_one", status: "new", absolute_path: __filename, check: true } },
9
+ { props: { id: 103, name: "bottom_one", status: "new", absolute_path: __filename, check: true } },
10
+ { props: { id: 104, name: "sync_all", status: "done", absolute_path: __filename, check: true } },
11
+ { props: { id: 105, name: "status", status: "delete", absolute_path: __filename, check: true } },
12
+ { props: { id: 106, name: "name", status: "test", absolute_path: __filename, check: true } },
13
+ { props: { id: 107, name: "version", status: "new", 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
+ t.id = props.id
21
+ t.log = props.log
22
+ t.name = props.name
23
+ t.status = props.status
24
+ t.path = props.relative_path
25
+ t.absolute_path = props.absolute_path
26
+ t.errors = false
27
+ t.error_msg = 'none'
28
+
29
+ // if (t.id == 104) {
30
+ // t.errors = true
31
+ // t.error_msg = `some sort of error here`
32
+ // }
33
+ t.base_queue_process_function = t.a_cool_function
34
+
35
+ t.do_checks = t.do_checks.bind(t)
36
+ t.a_cool_function = t.a_cool_function.bind(t)
37
+ t.base_queue_process_function = t.base_queue_process_function.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
+ a_cool_function(callback) {
82
+ let t = this
83
+ t.log({ msg: `processing object id ${t.id} name(${t.name}) status(${t.status}). 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}) status(${t.status})`}})
88
+ }
89
+ }
90
+
91
+ var qRequire = new file_queue()
92
+
93
+ qRequire.init().process({
94
+ appender: "json_name",
95
+ exclude_logMsg: ["debug", "silly", "info"], /* default [] */
96
+ process_objects: [file_object],
97
+ include_names: ["all", "status", "version"],
98
+ data_to_process_array: file_data
99
+ }).then((success) => {
100
+ qRequire.logMsg({ msg: `test success: json name matching objects processed with no errors`.success.italic.bold, type: "success" })
101
+ }, (error) => {
102
+ if (typeof error == "string") {
103
+ qRequire.logMsg({ msg: `error: ${error}`.error.italic.bold, type: "error" })
104
+ } else {
105
+ let add_s = (error.error_count > 1) ? 's' : ''
106
+ qRequire.logMsg({ msg: `${error.error_count} error${add_s} detected`.error.italic.bold, type: "error" })
107
+ }
108
+ })
109
+
@@ -0,0 +1,109 @@
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", status: "new", absolute_path: __filename, check: true } },
7
+ { props: { id: 101, name: "func_all", status: "done", absolute_path: __filename, check: true } },
8
+ { props: { id: 102, name: "top_one", status: "new", absolute_path: __filename, check: true } },
9
+ { props: { id: 103, name: "bottom_one", status: "new", absolute_path: __filename, check: true } },
10
+ { props: { id: 104, name: "sync_all", status: "done", absolute_path: __filename, check: true } },
11
+ { props: { id: 105, name: "status", status: "delete", absolute_path: __filename, check: true } },
12
+ { props: { id: 106, name: "name", status: "test", absolute_path: __filename, check: true } },
13
+ { props: { id: 107, name: "version", status: "new", 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
+ t.id = props.id
21
+ t.log = props.log
22
+ t.name = props.name
23
+ t.status = props.status
24
+ t.path = props.relative_path
25
+ t.absolute_path = props.absolute_path
26
+ t.errors = false
27
+ t.error_msg = 'none'
28
+
29
+ // if (t.id == 104) {
30
+ // t.errors = true
31
+ // t.error_msg = `some sort of error here`
32
+ // }
33
+ t.base_queue_process_function = t.a_cool_function
34
+
35
+ t.do_checks = t.do_checks.bind(t)
36
+ t.a_cool_function = t.a_cool_function.bind(t)
37
+ t.base_queue_process_function = t.base_queue_process_function.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
+ a_cool_function(callback) {
82
+ let t = this
83
+ t.log({ msg: `processing object id ${t.id} name(${t.name}) status(${t.status}). 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}) status(${t.status})`}})
88
+ }
89
+ }
90
+
91
+ var qRequire = new file_queue()
92
+
93
+ qRequire.init().process({
94
+ appender: "json_name",
95
+ exclude_logMsg: ["debug", "silly", "info"], /* default [] */
96
+ process_objects: [file_object],
97
+ exclude_names: ["all", "status", "version"],
98
+ data_to_process_array: file_data
99
+ }).then((success) => {
100
+ qRequire.logMsg({ msg: `test success: json name non matching objects processed with no errors`.success.italic.bold, type: "success" })
101
+ }, (error) => {
102
+ if (typeof error == "string") {
103
+ qRequire.logMsg({ msg: `error: ${error}`.error.italic.bold, type: "error" })
104
+ } else {
105
+ let add_s = (error.error_count > 1) ? 's' : ''
106
+ qRequire.logMsg({ msg: `${error.error_count} error${add_s} detected`.error.italic.bold, type: "error" })
107
+ }
108
+ })
109
+
@@ -0,0 +1,110 @@
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", status: "new", absolute_path: __filename, check: true } },
7
+ { props: { id: 101, name: "func_all", status: "done", absolute_path: __filename, check: true } },
8
+ { props: { id: 102, name: "top_one", status: "new", absolute_path: __filename, check: true } },
9
+ { props: { id: 103, name: "bottom_one", status: "new", absolute_path: __filename, check: true } },
10
+ { props: { id: 104, name: "sync_all", status: "done", absolute_path: __filename, check: true } },
11
+ { props: { id: 105, name: "status", status: "delete", absolute_path: __filename, check: true } },
12
+ { props: { id: 106, name: "name", status: "test", absolute_path: __filename, check: true } },
13
+ { props: { id: 107, name: "version", status: "new", 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
+ t.id = props.id
21
+ t.log = props.log
22
+ t.name = props.name
23
+ t.status = props.status
24
+ t.path = props.relative_path
25
+ t.absolute_path = props.absolute_path
26
+ t.errors = false
27
+ t.error_msg = 'none'
28
+
29
+ // if (t.id == 104) {
30
+ // t.errors = true
31
+ // t.error_msg = `some sort of error here`
32
+ // }
33
+ t.base_queue_process_function = t.a_cool_function
34
+
35
+ t.do_checks = t.do_checks.bind(t)
36
+ t.a_cool_function = t.a_cool_function.bind(t)
37
+ t.base_queue_process_function = t.base_queue_process_function.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
+ a_cool_function(callback) {
82
+ let t = this
83
+ t.log({ msg: `processing object id ${t.id} name(${t.name}) status(${t.status}). 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}) status(${t.status})`}})
88
+ }
89
+ }
90
+
91
+ var qRequire = new file_queue()
92
+
93
+ qRequire.init().process({
94
+ appender: "json_status",
95
+ exclude_logMsg: ["debug", "silly", "info"], /* default [] */
96
+ process_objects: [file_object],
97
+ include_names: ["all", "status"],
98
+ data_to_process_array: file_data
99
+ }).then((success) => {
100
+ qRequire.logMsg({ msg: `test success: json status matching objects processed with no errors`.success.italic.bold, type: "success" })
101
+ }, (error) => {
102
+ if (typeof error == "string") {
103
+ qRequire.logMsg({ msg: `error: ${error}`.error.italic.bold, type: "error" })
104
+
105
+ } else {
106
+ let add_s = (error.error_count > 1) ? 's' : ''
107
+ qRequire.logMsg({ msg: `${error.error_count} error${add_s} detected`.error.italic.bold, type: "error" })
108
+ }
109
+ })
110
+