file-obj-queue 1.0.24 → 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,128 +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("./local_queuejson/app")
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
- parent: t
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
- }
47
+ return new Promise((resolve, reject) => {
48
+ t.app_resolve = resolve
49
+ t.app_reject = reject
50
+
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
+ })
128
63
  }
129
64
 
130
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,14 +2,14 @@
2
2
  "author": {
3
3
  "name": "Jim Manton"
4
4
  },
5
- "version": "1.0.24",
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
13
  "queuejson": "^9.0.11",
14
14
  "valid-path": "^2.1.0"
15
15
  },
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,14 +6,14 @@ const packageMock = {
6
6
  "author": {
7
7
  "name": "Jim Manton"
8
8
  },
9
- "version": "1.0.24",
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
17
  "queuejson": "^9.0.11",
18
18
  "valid-path": "^2.1.0"
19
19
  },
@@ -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
 
@@ -1,236 +0,0 @@
1
-
2
- /*
3
- * @author Jim Manton: jrman@risebroadband.net
4
- * @since 2022-12-11
5
- * apps.js
6
- */
7
-
8
- let cc = require("node-console-colors"),
9
- all = require("./lib/appenders/all"),
10
- file_requre_data = [
11
- { props: { id: 100, name: "all", path: "./lib/appenders/all.js", absolute_path: __filename, check: true } }
12
- ]
13
-
14
- exports = module.exports = class QueueJson {
15
- constructor(props) {
16
- let t = this, fname = `app constructor`
17
- try {
18
- console.log(`${fname} 4000`, { "type": "debug" });
19
- t.class_obj_array = [];
20
- t.appenders = [{ name: 'all', obj: null }]
21
-
22
- t.props = props
23
- t.props.getParent = t.getParent
24
-
25
- if (typeof t.props != 'undefined' && typeof t.props.debug != 'undefined') {
26
- t.debug = t.props.debug
27
- } else {
28
- throw new Error(`props is not defined`)
29
- }
30
-
31
- t.file_obj_queue = t.props.parent //jrm debug 1/30
32
- // t.file_obj_queue = new file_queue().init({ input_data: file_requre_data }) //jrm debug 1/29
33
- console.log(`jrm debug 1/31 getFileObj 1202 (${typeof t.file_obj_queue})`)
34
-
35
- t.init = t.init.bind(t)
36
- t.process = t.process.bind(t)
37
- t.getParent = t.getParent.bind(t)
38
- t.logMsg = t.logMsg.bind(t)
39
-
40
- t.logMsg(`${fname} 4001`, { "type": "debug" });
41
-
42
- return t
43
- } catch (e) {
44
- t.logMsg(`${fname}: ${e}`, { "type": "error" })
45
- }
46
- }
47
-
48
- getParent = () => {
49
- return this
50
- }
51
-
52
- get_class_obj_array = () => {
53
- return this.class_obj_array
54
- }
55
-
56
- init = (props) => {
57
- let t = this, fname = `app init`, add = false, co, file_obj, obj
58
- try {
59
- t.logMsg(`${fname} appender(${t.props.appender})`, { "type": "debug" })
60
- // t.file_obj_queue = new file_queue().init({ input_data: file_requre_data }) //jrm debug 1/31
61
- t.logMsg(`${fname} jrm debug 1/31 SHOULD BE HERE`, { "type": "debug" })
62
- t.all = new all(t.props)
63
- return t
64
-
65
-
66
- // add = true
67
-
68
- // file_obj = t.file_obj_queue.getFileObject()
69
- // if (typeof t.props != `undefined`) {
70
- // if (typeof t.props.appender != `undefined` &&
71
- // typeof t.props.appender == 'string') {
72
- // t.props.getParent = t.getParent
73
- // file_obj.map((jsObj, i) => {
74
- // if (jsObj.name == t.props.appender) {
75
- // obj = require(jsObj.path)
76
- // eval(`t.${jsObj.name} = new obj(t.props)`)
77
- // }
78
- // })
79
- // }
80
- // return t
81
- // }
82
- // return t
83
-
84
- // process.exit(22);
85
-
86
- try {
87
- try {
88
- if (typeof props.input_data != 'undefined') {
89
- props.input_data.map((dat, i) => {
90
- add = false
91
- switch (t.props.appender) {
92
- case 'top_one':
93
- if (i == 0)
94
- add = true
95
- break
96
- case 'bottom_one':
97
- if (i == (props.input_data.length - 1))
98
- add = true
99
- break
100
- case 'status':
101
- case 'by_status':
102
- try {
103
- if (props.matching.indexOf(dat.props.status) > -1)
104
- add = true
105
- } catch { }
106
- try {
107
- if (props.non_matching.indexOf(dat.props.status) == -1)
108
- add = true
109
- } catch { }
110
- break
111
- case 'name':
112
- case 'by_name':
113
- try {
114
- if (props.matching.indexOf(dat.props.name) > -1)
115
- add = true
116
- } catch { }
117
- try {
118
- if (props.non_matching.indexOf(dat.props.name) == -1)
119
- add = true
120
- } catch { }
121
- break
122
- case 'version':
123
- try {
124
- if (props.matching.indexOf(dat.props.version) > -1)
125
- add = true
126
- } catch { }
127
- try {
128
- if (props.non_matching.indexOf(dat.props.version) == -1)
129
- add = true
130
- } catch { }
131
- break
132
-
133
- default:
134
- add = true
135
- }
136
- if (add) {
137
- co = new t.props.class_obj(dat.props)
138
- if (typeof dat.props.function_name == 'string') {
139
- co._getFuncName = () => {
140
- return dat.props.function_name
141
- }
142
- }
143
- t.class_obj_array.push(co)
144
- }
145
- })
146
- } else
147
- throw new Error('no input data array defined.')
148
- } catch (e) {
149
- throw e
150
- }
151
-
152
- } catch (e) {
153
- throw `new class_obj: ${e}`
154
- }
155
-
156
- file_obj = t.file_obj_queue.getFileObject()
157
- if (typeof t.props != `undefined`) {
158
- if (typeof t.props.appender != `undefined` &&
159
- typeof t.props.appender == 'string') {
160
- t.props.getParent = t.getParent
161
- file_obj.map((jsObj, i) => {
162
- if (jsObj.name == t.props.appender) {
163
- obj = require(jsObj.path)
164
- eval(`t.${jsObj.name} = new obj(t.props)`)
165
- }
166
- })
167
- }
168
- return t
169
- }
170
- return t
171
- } catch (e) {
172
- t.logMsg(`${fname}: ${e}`, { "type": "error" })
173
- }
174
- }
175
-
176
- logMsg = (msg, props = {}) => {
177
- let t = this
178
- try {
179
- let t = this, tp
180
- if (typeof props != 'undefined' && typeof props.type != 'undefined') {
181
- switch (props.type) {
182
- case 'debug':
183
- if (!t.debug)
184
- return
185
- tp = "bg_dark_gray"
186
- break
187
- case 'error':
188
- tp = "fg_red"
189
- break
190
- case 'purple':
191
- tp = "bg_purple"
192
- break
193
- case 'success':
194
- tp = "fg_green"
195
- break
196
- case 'white':
197
- tp = "bg_white"
198
- break
199
- default:
200
- tp = 'bg_dark_gray'
201
- }
202
- console.log(cc.set(tp, msg))
203
- return t
204
- }
205
- throw new Error('No props.type included')
206
- } catch (e) {
207
- console.log(`app log: ${e.message} for message (${msg})`)
208
- }
209
- }
210
-
211
- process = () => {
212
- let t = this, fname = `local_queuejson app process`
213
- try {
214
- return t.all.process()
215
- } catch (e) {
216
- t.logMsg(`${fname}: ${e.message}.`, { "type": "error" })
217
- }
218
-
219
-
220
- // let t = this, fname = `app process`, file_obj, jsObj, i
221
- // let pro = { 'dat_array': [''] }
222
- // try {
223
- // file_obj = t.file_obj_queue.getFileObject()
224
- // for (i = 0; i < file_obj.length; i++) {
225
- // jsObj = file_obj[i]
226
- // if (jsObj.name == t.props.appender) {
227
- // pro.dat_array.push(`${jsObj.name}`)
228
- // return eval(`t.${jsObj.name}.process()`)
229
- // }
230
- // }
231
- // throw new Error('no appender found to process')
232
- // } catch (e) {
233
- // t.logMsg(`${fname}: ${e}`, { "type": "error" })
234
- // }
235
- }
236
- }
@@ -1,22 +0,0 @@
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 all extends base {
10
- constructor(props) {
11
- super(props)
12
- var t = this
13
- try {
14
- t.aname = 'all'
15
- t.parent.logMsg(`all constructor`, {"type": "debug"})
16
- return t
17
- } catch (e) {
18
- t.parent.logMsg(e, {"type": "error"})
19
- }
20
-
21
- }
22
- }
@@ -1,80 +0,0 @@
1
- /*
2
- * @author Jim Manton: jrman@risebroadband.net
3
- * @since 2022-12-11
4
- * base.js
5
- */
6
-
7
- var qObj = require("queueobj");
8
-
9
- exports = module.exports = class base {
10
- constructor(props) {
11
- let t = this, fname = `base constructor`
12
- try {
13
- t.parent = props.getParent()
14
- t.resolve_array = []
15
- t.reject_array = []
16
-
17
- t.qObj = new qObj()
18
- t.qObj.load({ appender: props.appender, stats: props.stats, log: t.parent.logMsg })
19
-
20
- t.process = t.process.bind(t)
21
- t.process_all = t.process_all.bind(t)
22
- return t
23
- } catch (e) {
24
- t.parent.logMsg(`${fname}: ${e}`, { "type": "error" })
25
- throw e
26
- }
27
- }
28
-
29
- process = (props) => {
30
- let t = this, fname = `base process`
31
- try {
32
- t.dt_start = new Date(); // start measuring time
33
-
34
- t.parent.logMsg(fname, { "type": "debug" })
35
- return new Promise((resolve, reject) => {
36
- t.resolve_array.push(resolve)
37
- t.reject_array.push(reject)
38
- t.process_all()
39
- });
40
- } catch (e) {
41
- t.parent.logMsg(`${fname}: ${e}`, { "type": "error" })
42
- }
43
- }
44
-
45
- process_all = () => {
46
- let t = this, fname = `base process_all`, coa
47
- try {
48
- t.parent.logMsg(fname, { "type": "debug" })
49
-
50
- coa = t.parent.get_class_obj_array()
51
-
52
- if (coa.length == 0) {
53
- t.reject_array[0]({ error: 'no matching data to process' })
54
- }
55
-
56
- coa.map((dat, i) => {
57
- dat.log = t.log
58
- if (typeof t.qObj == 'undefined')
59
- throw new Error(`qObj does not exist`)
60
-
61
- if (typeof dat._getFuncName == 'function') {
62
- t.parent.logMsg(`${fname}: function name(${dat._getFuncName()})`, { "type": "debug" })
63
-
64
- t.qObj.add(eval(`dat.${dat._getFuncName()}`))
65
- } else {
66
- t.qObj.add(dat)
67
- }
68
- })
69
-
70
- t.qObj.process({}).then((res) => {
71
- t.resolve_array[0]({ res })
72
- }, (err) => {
73
- t.reject_array[0]({ err })
74
- })
75
- } catch (e) {
76
- t.parent.logMsg(`${fname}: ${e}`, { "type": "error" })
77
- throw e
78
- }
79
- }
80
- }