file-obj-queue 1.0.23 → 2.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/app.js CHANGED
@@ -3,132 +3,63 @@
3
3
  * Main processing app
4
4
  */
5
5
 
6
- let colors = require('node-console-colors'),
7
- fs = require('fs'),
8
- validPath = require('valid-path')
9
-
10
- class file_obj {
11
- constructor(props) {
12
- let t = this
13
- t.id = props.id
14
- t.log = props.log
15
- t.name = props.name
16
- t.path = props.path
17
- t.absolute_path = props.absolute_path
18
- t.status = 'init'
19
- t.errors = false
20
- t.error_msg = 'none'
21
-
22
- t.process = t.process.bind(t)
23
- t.do_checks = t.do_checks.bind(t)
24
-
25
- if (props.check) {
26
- t.do_checks()
27
- }
28
-
29
- return t
30
- }
31
-
32
- do_checks() {
33
- let t = this, path_to_check,
34
- last_item = t.absolute_path.split("\\").pop(),
35
- check_file = t.absolute_path.split(last_item)[0], check_path = t.path.split('/')
36
-
37
- check_file = check_file.replace(/\\/g, "/");
38
- path_to_check = validPath(t.path);
39
-
40
- if (!path_to_check.valid) {
41
- t.errors = true
42
- t.error_msg = `id = ${t.id} name(${t.name}) Error in ${path_to_check.data.input}: ${path_to_check.error})`
43
- }
44
-
45
- check_path.map((dat, i) => {
46
- if (/^[a-zA-Z._]+$/.test(dat)) {
47
- if (dat != '.')
48
- check_file += dat + '/'
49
- }
50
- })
51
- check_file = check_file.slice(0, -1)
52
- try {
53
- if (!fs.existsSync(check_file)) {
54
- t.errors = true
55
- t.error_msg = `id = ${t.id} name(${t.name}) file (${check_file} does not exist)`
56
- }
57
- } catch (e) {
58
- e.message = "file_obj do_checks error: " + e.message
59
- throw (e)
60
- }
61
- }
62
-
63
- process(callback) {
64
- let t = this
65
- if (t.errors)
66
- callback({ error: { msg: t.error_msg } })
67
- else
68
- callback({ success: { msg: `id = ${t.id} name(${t.name})` } })
69
- }
70
- }
6
+ let colors = require('colors'),
7
+ base_queue = require("./base_queue/app")
8
+
9
+ colors.setTheme({
10
+ silly: 'rainbow',
11
+ input: 'grey',
12
+ verbose: 'cyan',
13
+ prompt: 'grey',
14
+ info: 'green',
15
+ data: 'grey',
16
+ help: 'cyan',
17
+ warn: 'yellow',
18
+ debug: 'blue',
19
+ error: 'red',
20
+ success: 'green'
21
+ });
71
22
 
72
23
  exports = module.exports = class FilesQueue {
73
24
  constructor() {
74
25
  try {
75
26
  var t = this
27
+ t.app_resolve = null
28
+ t.app_reject = null
29
+ t.successMsg = ''
30
+
76
31
  t.logMsg = t.logMsg.bind(t)
77
- t.init = t.init.bind(t)
32
+ t.process = t.process.bind(t)
78
33
  t.getFileObject = t.getFileObject.bind(t)
79
- t.json_queue = require("queuejson")
80
- t.qJson = null
81
34
 
82
- t.logMsg(`FilesQueue.constructor`)
35
+ t.logMsg(`FilesQueue.constructor`.debug)
83
36
 
84
37
  return t
85
38
  } catch (e) {
86
- e.message = "FilesQueue app.js constructor error: " + e.message
39
+ e.message = `FilesQueue app.js constructor error: ${e.message}`.error
87
40
  throw (e)
88
41
  }
89
42
  }
90
43
 
91
- init(props = {}) {
44
+ process(props = {}) {
92
45
  let t = this
93
- try {
94
- if (t.qJson == null) {
95
- if (typeof props.input_data == 'undefined')
96
- throw new Error('props.input_data is not defined')
97
- try {
98
- t.logMsg(`jrm debug 1/29 8800`)
99
- t.qJson = new t.json_queue({
100
- class_obj: file_obj,
101
- appender: 'all',
102
- stats: true,
103
- debug: true,
104
- file_obj_queue: t.getFileObj //jrm debug 1/31
105
- })
106
- t.logMsg(`jrm debug 1/29 8801`)
107
- } catch (e) {
108
- e.message = "queuejson error: " + e.message
109
- t.logMsg(e.message)
110
- throw (e)
111
- }
112
- try {
113
- t.qJson.init({ input_data: props.input_data })
114
- t.qJson.process()
115
- } catch (e) {
116
- e.message = "queuejson.init error: " + e.message
117
- t.logMsg(e.message)
118
- throw (e)
119
- }
120
46
 
121
- }
122
- return t
123
- } catch (e) {
124
- e.message = "FilesQueue app.js init error: " + e.message
125
- t.logMsg(e.message)
126
- throw (e)
127
- }
128
- }
47
+ return new Promise((resolve, reject) => {
48
+ t.app_resolve = resolve
49
+ t.app_reject = reject
129
50
 
130
- getFileObj(){
131
- return this
51
+ if (typeof props.data_to_process_array == 'undefined')
52
+ t.app_reject('base_queue no props.data_to_process_array')
53
+
54
+ if (typeof props.appender == 'undefined')
55
+ t.app_reject('base_queue no props.appender')
56
+
57
+ if (typeof props.process_objects == 'undefined')
58
+ t.app_reject(`props.process_objects not defined`)
59
+
60
+ props.parent = t
61
+ t.base_queue = new base_queue().load(props).process()
62
+ })
132
63
  }
133
64
 
134
65
  getFileObject() {
@@ -0,0 +1,146 @@
1
+
2
+ /*
3
+ * @author Jim Manton: jrman@risebroadband.net
4
+ * @since 2023-02-02
5
+ * apps.js
6
+ */
7
+
8
+ let cc = require("colors"),
9
+ file_requre_data = [
10
+ { props: { id: 100, name: "all", path: "./lib/appenders/all.js", absolute_path: __filename, check: true } }
11
+ ]
12
+
13
+ cc.setTheme({
14
+ silly: 'rainbow',
15
+ input: 'grey',
16
+ verbose: 'cyan',
17
+ prompt: 'grey',
18
+ info: 'green',
19
+ data: 'grey',
20
+ help: 'cyan',
21
+ warn: 'yellow',
22
+ debug: 'blue',
23
+ error: 'red'
24
+ });
25
+
26
+
27
+ class process_object {
28
+ constructor(props) {
29
+ let t = this
30
+ t.parent = props.parent
31
+ t.status = 'process'
32
+ t.objs = t.parent.getParent().getObjs()
33
+ }
34
+
35
+ process() {
36
+ let t = this
37
+ }
38
+
39
+ continueProcessing() {
40
+ let t = this
41
+ }
42
+
43
+ getStatus() {
44
+ return this.status
45
+ }
46
+
47
+ setStatus(v) {
48
+ this.status = v
49
+ }
50
+ }
51
+
52
+ exports = module.exports = class BaseQueue {
53
+ constructor(props = {}) {
54
+ let t = this, fname = `BaseQueue app constructor`
55
+ try {
56
+ t.parent = null
57
+ t.appenders_dir = './appenders/'
58
+ t.appender = null
59
+
60
+ t.logMsg = t.logMsg.bind(t)
61
+ t.init = t.init.bind(t)
62
+ t.load = t.load.bind(t)
63
+ t.process = t.process.bind(t)
64
+ t.set_base_promise = t.set_base_promise.bind(t)
65
+ t.base_promise = null
66
+ t.base_resolve = null
67
+ t.base_reject = null
68
+
69
+ t.set_base_promise()
70
+
71
+ return t
72
+ } catch (e) {
73
+ t.logMsg(`${fname}: ${e.message}`.error)
74
+ }
75
+ }
76
+
77
+ set_base_promise() {
78
+ let t = this, fname = `BaseQueue set_base_promise`
79
+
80
+ t.base_promise = new Promise((resolve, reject) => {
81
+ t.base_resolve = resolve
82
+ t.base_reject = reject
83
+ })
84
+
85
+ t.base_promise.then(function (success) {
86
+ t.parent.app_resolve(success)
87
+ }).catch(function (err) {
88
+ t.parent.app_reject(err)
89
+ })
90
+
91
+ }
92
+
93
+ init(props = {}) {
94
+ let t = this, fname = `BaseQueue init`
95
+ }
96
+
97
+ load(props = {}) {
98
+ let t = this, fname = `BaseQueue load`, a, app, req
99
+
100
+ if (typeof props.parent == 'undefined')
101
+ t.base_reject(`${fname}: props.parent not defined`)
102
+
103
+ t.parent = props.parent
104
+ props.parent = t
105
+ app = props.appender
106
+ a = t.appenders_dir + app + '.js'
107
+ req = require(a)
108
+ t.parent.logMsg(`${fname} loading appender(${a})`.debug)
109
+ t.appender = new req(props)
110
+ return t
111
+ }
112
+
113
+ process() {
114
+ let t = this, fname = `BaseQueue process`, res, error_count = 0
115
+ try {
116
+ t.logMsg(`${fname}`.debug)
117
+
118
+ res = t.appender.init().process().get_results_array()
119
+ res.map((json, i) => {
120
+ if (typeof json.success != "undefined")
121
+ t.logMsg(`${JSON.stringify(json)}`.success)
122
+ if (typeof json.error != "undefined") {
123
+ t.logMsg(`${JSON.stringify(json)}`.error)
124
+ error_count++
125
+ }
126
+ })
127
+ if (error_count) {
128
+ res.error_count = error_count
129
+ t.base_reject(res)
130
+ } else
131
+ t.base_resolve(res)
132
+ } catch (e) {
133
+ t.base_reject(`${fname}: ${e.message}.`)
134
+ }
135
+ }
136
+
137
+ logMsg(msg, props = {}) {
138
+ let t = this
139
+ try {
140
+ console.log(msg)
141
+ return t
142
+ } catch (e) {
143
+ t.base_reject(`BaseQueue log: ${e.message} for message (${msg})`)
144
+ }
145
+ }
146
+ }
@@ -0,0 +1,77 @@
1
+ /*
2
+ * @author Jim Manton: jrman@risebroadband.net
3
+ * @since 2023-02-03
4
+ * base.js
5
+ */
6
+
7
+ exports = module.exports = class base {
8
+ constructor(props) {
9
+ let t = this, fname = `base appenders constructor`
10
+ try {
11
+ t.parent = props.parent
12
+ t.parent.logMsg(`${fname}`.debug)
13
+ t.class_obj_array = []
14
+ t.data_to_process_array = []
15
+ t.objects_to_process = []
16
+ t.results_array = []
17
+ t.base_name_appender = ''
18
+
19
+ if (typeof props.data_to_process_array == 'undefined')
20
+ throw new Error(`props.data_to_process_array not defined`)
21
+
22
+ if (typeof props.process_objects == 'undefined')
23
+ throw new Error(`props.process_objects not defined`)
24
+
25
+ if (typeof props.appender == 'undefined')
26
+ throw new Error(`appender not defined)`)
27
+
28
+ t.base_name_appender = props.appender
29
+ t.data_to_process_array = props.data_to_process_array
30
+ t.objects_to_process = props.process_objects
31
+
32
+ t.init = t.init.bind(t)
33
+ t.get_objects_to_process = t.get_objects_to_process.bind(t)
34
+ t.get_data_to_process_array = t.get_data_to_process_array.bind(t)
35
+ t.process = t.process.bind(t)
36
+ t.get_results_array = t.get_results_array.bind(t)
37
+
38
+ return t
39
+ } catch (e) {
40
+ t.parent.base_reject(`${fname} error: ${e.message})`)
41
+ }
42
+ }
43
+
44
+ process (props = {}) {
45
+ var t = this, fname = `base.process`
46
+ try {
47
+ t.parent.logMsg(`${fname}`.debug)
48
+
49
+ return t
50
+ } catch (e) {
51
+ t.parent.base_reject(`${fname} error: ${e.message})`)
52
+ }
53
+ }
54
+
55
+ get_results_array () {
56
+ return this.results_array
57
+ }
58
+
59
+ get_data_to_process_array () {
60
+ return this.data_to_process_array
61
+ }
62
+
63
+ get_objects_to_process () {
64
+ return this.objects_to_process
65
+ }
66
+
67
+ init (props = {}) {
68
+ var t = this, fname = `base.init`
69
+ try {
70
+
71
+ t.parent.logMsg(`${fname}`.debug)
72
+ return t
73
+ } catch (e) {
74
+ t.parent.base_reject(`${fname} error: ${e.message})`)
75
+ }
76
+ }
77
+ }
@@ -0,0 +1,70 @@
1
+ /*
2
+ * @author Jim Manton: jrman@risebroadband.net
3
+ * @since 2022-12-11
4
+ * all.ts
5
+ */
6
+
7
+ var base = require('./base.js')
8
+
9
+ exports = module.exports = class json_all extends base {
10
+ constructor(props) {
11
+ super(props)
12
+ var t = this, fname = 'json_all.constructor'
13
+ try {
14
+ t.aname = 'json_all'
15
+ t.main_process_objects = []
16
+
17
+ if (t.base_name_appender != t.aname)
18
+ throw new Error(`(${t.base_name_appender}) does not equal the appender name (${t.aname}))`)
19
+
20
+ t.parent.logMsg(`${fname}`.debug)
21
+
22
+ t.init = t.init.bind(t)
23
+ t.process = t.process.bind(t)
24
+
25
+ return t
26
+ } catch (e) {
27
+ t.parent.base_reject(`${fname} error: ${e.message})`)
28
+ }
29
+ }
30
+
31
+ init (props = {}) {
32
+ var t = this, fname = `json_all.init`, gotp, gdtpa, obj
33
+ try {
34
+ t.parent.logMsg(`${fname}`.debug)
35
+
36
+ if (typeof t.get_objects_to_process()[0] == "undefined")
37
+ throw new Error(`get_objects_to_process[0] has no data`)
38
+
39
+ t.get_data_to_process_array().map((dat, i)=>{
40
+ dat.props.log = t.parent.logMsg
41
+ obj = t.get_objects_to_process()[0]
42
+ t.main_process_objects.push(new obj(dat.props))
43
+ })
44
+
45
+ super.init(props)
46
+ return t
47
+ } catch (e) {
48
+ t.parent.base_reject(`${fname} error: ${e.message})`)
49
+ }
50
+ }
51
+
52
+ process (props = {}) {
53
+ var t = this, fname = `json_all.process`
54
+ try {
55
+ t.parent.logMsg(`${fname} length(${t.main_process_objects.length})`.debug)
56
+
57
+ t.main_process_objects.map((obj, i)=>{
58
+ obj.process((res)=>{
59
+ // t.parent.logMsg(`${fname}${JSON.stringify(res)})`.debug)
60
+ t.results_array.push(res)
61
+ })
62
+ })
63
+
64
+ super.process(props)
65
+ return t
66
+ } catch (e) {
67
+ t.parent.base_reject(`${fname} error: ${e.message})`)
68
+ }
69
+ }
70
+ }
package/package.json CHANGED
@@ -2,15 +2,15 @@
2
2
  "author": {
3
3
  "name": "Jim Manton"
4
4
  },
5
- "version": "1.0.23",
5
+ "version": "2.0.0",
6
6
  "bundleDependencies": [],
7
7
  "dependencies": {
8
8
  "chai": "^4.3.7",
9
+ "colors": "^1.4.0",
9
10
  "diffler": "^2.0.4",
10
11
  "fs": "^0.0.1-security",
11
12
  "mocha": "^10.2.0",
12
- "node-console-colors": "^1.1.4",
13
- "queuejson": "^9.0.9",
13
+ "queuejson": "^9.0.11",
14
14
  "valid-path": "^2.1.0"
15
15
  },
16
16
  "scripts": {
package/test/app.js CHANGED
@@ -7,10 +7,6 @@ describe('app', function () {
7
7
  application = require('../app.js')
8
8
  assert(app = new application())
9
9
  })
10
-
11
- it('app.init is a function', function () {
12
- assert(typeof app.init == 'function')
13
- })
14
10
 
15
11
  it('app.logMsg is a function', function () {
16
12
  assert(typeof app.logMsg == 'function')
@@ -23,12 +19,12 @@ describe('app', function () {
23
19
 
24
20
  describe('require', function () {
25
21
 
26
- it('node-console-colors', function () {
27
- assert(require('node-console-colors'))
22
+ it('colors', function () {
23
+ assert(require('colors'))
28
24
  })
29
25
 
30
- it('queuejson', function () {
31
- assert(require('queuejson'))
26
+ it('base_queue', function () {
27
+ assert(require('../base_queue/app'))
32
28
  })
33
29
 
34
30
  it('fs', function () {
package/test/package.js CHANGED
@@ -6,15 +6,15 @@ const packageMock = {
6
6
  "author": {
7
7
  "name": "Jim Manton"
8
8
  },
9
- "version": "1.0.23",
9
+ "version": "2.0.0",
10
10
  "bundleDependencies": [],
11
11
  "dependencies": {
12
12
  "chai": "^4.3.7",
13
+ "colors": "^1.4.0",
13
14
  "diffler": "^2.0.4",
14
15
  "fs": "^0.0.1-security",
15
16
  "mocha": "^10.2.0",
16
- "node-console-colors": "^1.1.4",
17
- "queuejson": "^9.0.9",
17
+ "queuejson": "^9.0.11",
18
18
  "valid-path": "^2.1.0"
19
19
  },
20
20
  "scripts": {
@@ -4,9 +4,9 @@
4
4
  * lib/appenders/base.js
5
5
  */
6
6
 
7
- var colors = require('node-console-colors')
7
+ var colors = require('colors')
8
8
 
9
- class process_all_obj {
9
+ class process_object {
10
10
  constructor(props) {
11
11
  let t = this
12
12
  t.parent = props.parent
@@ -82,7 +82,7 @@ class process_all_obj {
82
82
  throw e
83
83
  }
84
84
  } catch (e) {
85
- e.message = `process_all_obj error: ${e.message} `
85
+ e.message = `process_object error: ${e.message} `
86
86
  throw e
87
87
  }
88
88
  }
@@ -113,7 +113,7 @@ exports = module.exports = class base {
113
113
  t.getParent = props.getParent
114
114
  t.dt_start = null
115
115
  t.dt_end = null
116
- t.process_all_obj = null
116
+ t.process_object = null
117
117
  t.pro_props = []
118
118
 
119
119
  t.process = t.process.bind(this)
@@ -155,15 +155,15 @@ exports = module.exports = class base {
155
155
 
156
156
  process_all = () => {
157
157
  let t = this, _continue
158
- if (t.process_all_obj == null) {
159
- t.process_all_obj = new process_all_obj({ parent: t })
158
+ if (t.process_object == null) {
159
+ t.process_object = new process_object({ parent: t })
160
160
  }
161
161
 
162
162
  _continue = false
163
163
  try {
164
- switch (t.process_all_obj.getStatus()) {
164
+ switch (t.process_object.getStatus()) {
165
165
  case 'process':
166
- t.process_all_obj.process()
166
+ t.process_object.process()
167
167
  _continue = true
168
168
  break
169
169
  case 'finish with errors':
@@ -175,7 +175,7 @@ exports = module.exports = class base {
175
175
  case 'wait':
176
176
  return
177
177
  default:
178
- throw new Error(`status(${t.process_all_obj.getStatus()}) does not exist`)
178
+ throw new Error(`status(${t.process_object.getStatus()}) does not exist`)
179
179
  }
180
180
 
181
181
  if (_continue)
package/tests/files.js CHANGED
@@ -1,5 +1,7 @@
1
- var colors = require('node-console-colors'),
2
- file_queue = require("../app.js")
1
+ var colors = require('colors'),
2
+ file_queue = require("../app.js"),
3
+ fs = require('fs'),
4
+ validPath = require('valid-path')
3
5
 
4
6
  var file_data = [
5
7
  { props: { id: 100, name: "all", path: "./appenders/all.js", absolute_path: __filename, check: true } },
@@ -12,9 +14,77 @@ var file_data = [
12
14
  { props: { id: 107, name: "version", path: "./appenders/version.js", absolute_path: __filename, check: true } }
13
15
  ]
14
16
 
15
- console.log(`jrm debug 1/29 2200`)
16
- var qRequire = new file_queue().init({ input_data: file_data })
17
- console.log(`jrm debug 1/29 2201`)
18
17
 
19
- console.log(`test complete`)
18
+ var file_object = class file_obj {
19
+ constructor(props) {
20
+ let t = this
21
+ t.id = props.id
22
+ t.log = props.log
23
+ t.name = props.name
24
+ t.path = props.path
25
+ t.absolute_path = props.absolute_path
26
+ t.status = 'init'
27
+ t.errors = false
28
+ t.error_msg = 'none'
29
+
30
+ t.process = t.process.bind(t)
31
+ t.do_checks = t.do_checks.bind(t)
32
+
33
+ if (props.check) {
34
+ t.do_checks()
35
+ }
36
+
37
+ return t
38
+ }
39
+
40
+ do_checks() {
41
+ let t = this, path_to_check,
42
+ last_item = t.absolute_path.split("\\").pop(),
43
+ check_file = t.absolute_path.split(last_item)[0], check_path = t.path.split('/')
44
+
45
+ check_file = check_file.replace(/\\/g, "/");
46
+ path_to_check = validPath(t.path);
47
+
48
+ if (!path_to_check.valid) {
49
+ t.errors = true
50
+ t.error_msg = `id = ${t.id} name(${t.name}) Error in ${path_to_check.data.input}: ${path_to_check.error})`
51
+ }
52
+
53
+ check_path.map((dat, i) => {
54
+ if (/^[a-zA-Z._]+$/.test(dat)) {
55
+ if (dat != '.')
56
+ check_file += dat + '/'
57
+ }
58
+ })
59
+ check_file = check_file.slice(0, -1)
60
+ try {
61
+ if (!fs.existsSync(check_file)) {
62
+ t.errors = true
63
+ t.error_msg = `id = ${t.id} name(${t.name}) file (${check_file} does not exist)`
64
+ }
65
+ } catch (e) {
66
+ e.message = "file_obj do_checks error: " + e.message
67
+ throw (e)
68
+ }
69
+ }
70
+
71
+ process(callback) {
72
+ let t = this
73
+ if (t.errors)
74
+ callback({ error: { msg: t.error_msg } })
75
+ else
76
+ callback({ success: { msg: `id = ${t.id} name(${t.name})` } })
77
+ }
78
+ }
79
+
80
+ var qRequire = new file_queue()
81
+
82
+ qRequire.process({ appender: "json_all",
83
+ process_objects: [file_object],
84
+ data_to_process_array: file_data }).then((success)=>{
85
+ qRequire.logMsg(`test success: all file objects processed with no errors`.success)
86
+ },(error)=>{
87
+ let add_s = (error.error_count > 1) ? 's' : ''
88
+ qRequire.logMsg(`${error.error_count} error${add_s} detected`.error)
89
+ })
20
90