base-queue 0.0.1

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.
@@ -0,0 +1,77 @@
1
+ /*
2
+ * @author Jim Manton: jrman@risebroadband.net
3
+ * @since 2023-2-5
4
+ * name.js
5
+ */
6
+
7
+ var base = require('./base.js'),
8
+ common_code = require('./common_code.js')
9
+
10
+ exports = module.exports = class name extends base {
11
+ constructor(props) {
12
+ super(props)
13
+ var t = this, fname = 'name.constructor'
14
+ try {
15
+ t.aname = 'name'
16
+ t.main_process_objects = []
17
+ t.common_code = new common_code({
18
+ parent: t,
19
+ log: t.parent.logMsg,
20
+ include_func: t.get_include_names,
21
+ exclude_func: t.get_exclude_names,
22
+ by_what: t.aname
23
+ })
24
+
25
+ if (t.appender != t.aname)
26
+ throw new Error(`(${t.appender}) does not equal the appender name (${t.aname}))`)
27
+
28
+ t.parent.logMsg({ msg: `${fname} objects to process count(${t.get_objects_to_process().length})`.debug, type: "debug" })
29
+
30
+ t.init = t.init.bind(t)
31
+ t.process = t.process.bind(t)
32
+
33
+ return t
34
+ } catch (e) {
35
+ e.message = `${fname} error: ${e.message})`
36
+ throw e
37
+ // t.parent.app_reject(`${fname} error: ${e.message})`)
38
+ }
39
+ }
40
+
41
+ init(props = {}) {
42
+ var t = this, fname = `name.init`, obj
43
+ try {
44
+ t.parent.logMsg({ msg: `${fname}`.debug, type: "debug" })
45
+
46
+ if (typeof t.get_objects_to_process()[0] == "undefined")
47
+ throw new Error(`get_objects_to_process[0] has no data`)
48
+
49
+ t.get_objects_to_process().map((dat, i) => {
50
+ dat = { props: { id: (i + 1), log: t.parent.logMsg } }
51
+ obj = t.get_objects_to_process()[i]
52
+ t.common_code.init({ obj: obj, dat: dat })
53
+ })
54
+
55
+ super.init(props)
56
+ return t
57
+ } catch (e) {
58
+ e.message = `${fname} error: ${e.message})`
59
+ throw e
60
+ // t.parent.app_reject(`${fname} error: ${e.message})`)
61
+ }
62
+ }
63
+
64
+ process(props = {}) {
65
+ var t = this, fname = `name.process`
66
+ try {
67
+ t.parent.logMsg({ msg: `${fname}`.debug, type: "debug" })
68
+
69
+ super.process(props)
70
+ return t
71
+ } catch (e) {
72
+ e.message = `${fname} error: ${e.message})`
73
+ throw e
74
+ // t.parent.app_reject(`${fname} error: ${e.message})`)
75
+ }
76
+ }
77
+ }
@@ -0,0 +1,77 @@
1
+ /*
2
+ * @author Jim Manton: jrman@risebroadband.net
3
+ * @since 2023-2-5
4
+ * status.js
5
+ */
6
+
7
+ var base = require('./base.js'),
8
+ common_code = require('./common_code.js')
9
+
10
+ exports = module.exports = class status extends base {
11
+ constructor(props) {
12
+ super(props)
13
+ var t = this, fname = 'status.constructor'
14
+ try {
15
+ t.aname = 'status'
16
+ t.main_process_objects = []
17
+ t.common_code = new common_code({
18
+ parent: t,
19
+ log: t.parent.logMsg,
20
+ include_func: t.get_include_status,
21
+ exclude_func: t.get_exclude_status,
22
+ by_what: t.aname
23
+ })
24
+
25
+ if (t.appender != t.aname)
26
+ throw new Error(`(${t.appender}) does not equal the appender name (${t.aname}))`)
27
+
28
+ t.parent.logMsg({ msg: `${fname} objects to process count(${t.get_objects_to_process().length})`.debug, type: "debug" })
29
+
30
+ t.init = t.init.bind(t)
31
+ t.process = t.process.bind(t)
32
+
33
+ return t
34
+ } catch (e) {
35
+ e.message = `${fname} error: ${e.message})`
36
+ throw e
37
+ // t.parent.app_reject(`${fname} error: ${e.message})`)
38
+ }
39
+ }
40
+
41
+ init(props = {}) {
42
+ var t = this, fname = `status.init`, obj, obj_a, is
43
+ try {
44
+ t.parent.logMsg({ msg: `${fname}`.debug, type: "debug" })
45
+
46
+ if (typeof t.get_objects_to_process()[0] == "undefined")
47
+ throw new Error(`get_objects_to_process[0] has no data`)
48
+
49
+ t.get_objects_to_process().map((dat, i) => {
50
+ dat = { props: { id: (i + 1), log: t.parent.logMsg } }
51
+ obj = t.get_objects_to_process()[i]
52
+ t.common_code.init({ obj: obj, dat: dat })
53
+ })
54
+
55
+ super.init(props)
56
+ return t
57
+ } catch (e) {
58
+ e.message = `${fname} error: ${e.message})`
59
+ throw e
60
+ // t.parent.app_reject(`${fname} error: ${e.message})`)
61
+ }
62
+ }
63
+
64
+ process(props = {}) {
65
+ var t = this, fname = `status.process`
66
+ try {
67
+ t.parent.logMsg({ msg: `${fname}`.debug, type: "debug" })
68
+
69
+ super.process(props)
70
+ return t
71
+ } catch (e) {
72
+ e.message = `${fname} error: ${e.message})`
73
+ throw e
74
+ // t.parent.app_reject(`${fname} error: ${e.message})`)
75
+ }
76
+ }
77
+ }
@@ -0,0 +1,67 @@
1
+ /*
2
+ * @author Jim Manton: jrman@risebroadband.net
3
+ * @since 2023-2-5
4
+ * top_one.js
5
+ */
6
+
7
+ var base = require('./base.js')
8
+
9
+ exports = module.exports = class top_one extends base {
10
+ constructor(props) {
11
+ super(props)
12
+ var t = this, fname = 'top_one.constructor'
13
+ try {
14
+ t.aname = 'top_one'
15
+ t.main_process_objects = []
16
+
17
+ if (t.appender != t.aname)
18
+ throw new Error(`(${t.appender}) does not equal the appender name (${t.aname}))`)
19
+
20
+ t.parent.logMsg({ msg: `${fname} objects to process count(${t.get_objects_to_process().length})`.debug, type: "debug" })
21
+
22
+ t.init = t.init.bind(t)
23
+ t.process = t.process.bind(t)
24
+
25
+ return t
26
+ } catch (e) {
27
+ e.message = `${fname} error: ${e.message})`
28
+ throw e
29
+ // t.parent.app_reject(`${fname} error: ${e.message})`)
30
+ }
31
+ }
32
+
33
+ init(props = {}) {
34
+ var t = this, fname = `top_one.init`, obj, dat
35
+ try {
36
+ t.parent.logMsg({ msg: `${fname}`.debug, type: "debug" })
37
+
38
+ if (typeof t.get_objects_to_process()[0] == "undefined")
39
+ throw new Error(`get_objects_to_process[0] has no data`)
40
+
41
+ obj = t.get_objects_to_process()[0]
42
+ dat = { props: { id: 1, log: t.parent.logMsg } }
43
+ t.main_process_objects.push(new obj(dat.props))
44
+
45
+ super.init(props)
46
+ return t
47
+ } catch (e) {
48
+ e.message = `${fname} error: ${e.message})`
49
+ throw e
50
+ // t.parent.app_reject(`${fname} error: ${e.message})`)
51
+ }
52
+ }
53
+
54
+ process(props = {}) {
55
+ var t = this, fname = `top_one.process`
56
+ try {
57
+ t.parent.logMsg({ msg: `${fname}`.debug, type: "debug" })
58
+
59
+ super.process(props)
60
+ return t
61
+ } catch (e) {
62
+ e.message = `${fname} error: ${e.message})`
63
+ throw e
64
+ // t.parent.app_reject(`${fname} error: ${e.message})`)
65
+ }
66
+ }
67
+ }
@@ -0,0 +1,85 @@
1
+ /*
2
+ * @author Jim Manton: jrman@risebroadband.net
3
+ * @since 2023-2-5
4
+ * version.js
5
+ */
6
+
7
+ var base = require('./base.js'),
8
+ common_code = require('./common_code.js')
9
+
10
+ exports = module.exports = class version extends base {
11
+ constructor(props) {
12
+ super(props)
13
+ var t = this, fname = 'version.constructor'
14
+ try {
15
+ t.aname = 'version'
16
+ t.main_process_objects = []
17
+ t.common_code = new common_code({
18
+ parent: t,
19
+ log: t.parent.logMsg,
20
+ include_func: t.get_include_version,
21
+ exclude_func: t.get_exclude_version,
22
+ by_what: t.aname
23
+ })
24
+
25
+ if (t.appender != t.aname)
26
+ throw new Error(`(${t.appender}) does not equal the appender name (${t.aname}))`)
27
+
28
+ t.parent.logMsg({ msg: `${fname} objects to process count(${t.get_objects_to_process().length})`.debug, type: "debug" })
29
+
30
+ t.init = t.init.bind(t)
31
+ t.process = t.process.bind(t)
32
+
33
+ return t
34
+ } catch (e) {
35
+ e.message = `${fname} error: ${e.message})`
36
+ throw e
37
+ // t.parent.app_reject(`${fname} error: ${e.message})`)
38
+ }
39
+ }
40
+
41
+ init(props = {}) {
42
+ var t = this, fname = `version.init`, obj, obj_a, is
43
+ try {
44
+ t.parent.logMsg({ msg: `${fname}`.debug, type: "debug" })
45
+
46
+ if (typeof t.get_objects_to_process()[0] == "undefined")
47
+ throw new Error(`get_objects_to_process[0] has no data`)
48
+
49
+ t.get_objects_to_process().map((dat, i) => {
50
+ dat = { props: { id: (i + 1), log: t.parent.logMsg } }
51
+ obj = t.get_objects_to_process()[i]
52
+ t.common_code.init({ obj: obj, dat: dat })
53
+
54
+ // is = t.get_include_version() jrm debug 2/23
55
+ // obj_a = new obj(dat.props)
56
+ // if (typeof obj_a != "undefined" &&
57
+ // typeof obj_a.version != "undefined" &&
58
+ // is.indexOf(obj_a.version) > -1) {
59
+ // t.main_process_objects.push(new obj(dat.props))
60
+ // }
61
+ })
62
+
63
+ super.init(props)
64
+ return t
65
+ } catch (e) {
66
+ e.message = `${fname} error: ${e.message})`
67
+ throw e
68
+ // t.parent.app_reject(`${fname} error: ${e.message})`)
69
+ }
70
+ }
71
+
72
+ process(props = {}) {
73
+ var t = this, fname = `version.process`
74
+ try {
75
+ t.parent.logMsg({ msg: `${fname}`.debug, type: "debug" })
76
+
77
+ super.process(props)
78
+ return t
79
+ } catch (e) {
80
+ e.message = `${fname} error: ${e.message})`
81
+ throw e
82
+ // t.parent.app_reject(`${fname} error: ${e.message})`)
83
+ }
84
+ }
85
+ }
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "author": {
3
+ "name": "Jim Manton"
4
+ },
5
+ "version": "0.0.1",
6
+ "bundleDependencies": [],
7
+ "dependencies": {
8
+ "chai": "^4.3.7",
9
+ "colors": "^1.4.0",
10
+ "diffler": "^2.0.4",
11
+ "fs": "^0.0.1-security",
12
+ "log-queue": "^1.0.0",
13
+ "mocha": "^10.2.0",
14
+ "valid-path": "^2.1.0"
15
+ },
16
+ "scripts": {
17
+ "start": "node app.ts",
18
+ "test": "mocha",
19
+ "ditched": "ditched -a",
20
+ "test_base": "node ./tests/base"
21
+ },
22
+ "keywords": [
23
+ "queue",
24
+ "processing",
25
+ "appenders",
26
+ "javascript",
27
+ "synchronous",
28
+ "objects",
29
+ "promises",
30
+ "mocha"
31
+ ],
32
+ "homepage": "https://github.com/jman717/base-queue",
33
+ "repository": {
34
+ "type": "git",
35
+ "url": "git+https://github.com/jman717/base-queue.git"
36
+ },
37
+ "deprecated": false,
38
+ "description": "Logging to console with eventual log4js-tagline support.",
39
+ "email": "jrman@risebroadband.net",
40
+ "license": "MIT",
41
+ "main": "app.js",
42
+ "name": "base-queue",
43
+ "start": "node app.js"
44
+ }
package/test/app.js ADDED
@@ -0,0 +1,29 @@
1
+ var assert = require('assert');
2
+
3
+ describe('app', function () {
4
+ let app, application
5
+
6
+ it('app.constructor should pass', function () {
7
+ application = require('../app.js')
8
+ assert(app = new application({ parent: null }))
9
+ })
10
+
11
+ it('app.process is a function', function () {
12
+ assert(typeof app.process == 'function')
13
+ })
14
+
15
+ it('app.load is a function', function () {
16
+ assert(typeof app.load == 'function')
17
+ })
18
+
19
+ it('app.init is a function', function () {
20
+ assert(typeof app.init == 'function')
21
+ })
22
+ })
23
+
24
+ describe('require', function () {
25
+
26
+ it('colors', function () {
27
+ assert(require('colors'))
28
+ })
29
+ })
@@ -0,0 +1,60 @@
1
+ const assert = require('assert'),
2
+ jsonHasDifferences = require('diffler'),
3
+ packagejson = require('../package.json')
4
+
5
+ const packageMock = {
6
+ "author": {
7
+ "name": "Jim Manton"
8
+ },
9
+ "version": "0.0.1",
10
+ "bundleDependencies": [],
11
+ "dependencies": {
12
+ "chai": "^4.3.7",
13
+ "colors": "^1.4.0",
14
+ "diffler": "^2.0.4",
15
+ "fs": "^0.0.1-security",
16
+ "log-queue": "^1.0.0",
17
+ "mocha": "^10.2.0",
18
+ "valid-path": "^2.1.0"
19
+ },
20
+ "scripts": {
21
+ "start": "node app.ts",
22
+ "test": "mocha",
23
+ "ditched": "ditched -a",
24
+ "test_base": "node ./tests/base"
25
+ },
26
+ "keywords": [
27
+ "queue",
28
+ "processing",
29
+ "appenders",
30
+ "javascript",
31
+ "synchronous",
32
+ "objects",
33
+ "promises",
34
+ "mocha"
35
+ ],
36
+ "homepage": "https://github.com/jman717/base-queue",
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "git+https://github.com/jman717/base-queue.git"
40
+ },
41
+ "deprecated": false,
42
+ "description": "Logging to console with eventual log4js-tagline support.",
43
+ "email": "jrman@risebroadband.net",
44
+ "license": "MIT",
45
+ "main": "app.js",
46
+ "name": "base-queue",
47
+ "start": "node app.js"
48
+ }
49
+
50
+ describe('package.json', function () {
51
+ it('should pass', function () {
52
+ const difference = jsonHasDifferences(packagejson, packageMock)
53
+ assert(JSON.stringify(difference) == "{}")
54
+ })
55
+
56
+ it('should fail', function () {
57
+ packageMock.version = '0'
58
+ assert(jsonHasDifferences(packagejson, packageMock))
59
+ })
60
+ })
package/tests/base.js ADDED
@@ -0,0 +1,101 @@
1
+
2
+ var tst1 = class test1 {
3
+ constructor(props) {
4
+ let t = this, fname = "test_all.test1.constructor"
5
+ t.log = props.log
6
+ t.id = props.id
7
+
8
+ t.process = t.process.bind(t)
9
+ }
10
+
11
+ process(callback) {
12
+ let t = this, fname = "test_all.test1.process"
13
+ t.log({ msg: `This object (${fname}) is id (${t.id}). Do stuff here`.bgBrightGreen, type: "info" })
14
+ callback({ success: { msg: `processing all test1` } })
15
+ }
16
+ }
17
+
18
+ var tst2 = class test2 {
19
+ constructor(props) {
20
+ let t = this, fname = "test_all.test2.constructor"
21
+ t.log = props.log
22
+ t.id = props.id
23
+
24
+ t.process = t.process.bind(t)
25
+ }
26
+
27
+ process(callback) {
28
+ let t = this, fname = "test_all.test2.process"
29
+ t.log({ msg: `This object (${fname}) is id (${t.id}). Do stuff here`.bgBrightGreen, type: "info" })
30
+ setTimeout(() => {
31
+ callback({ success: { msg: `processing all test2` } })
32
+ }, 4000)
33
+ }
34
+ }
35
+
36
+ var tst3 = class test3 {
37
+ constructor(props) {
38
+ let t = this, fname = "test_all.test3.constructor"
39
+ t.log = props.log
40
+ t.id = props.id
41
+
42
+ t.process = t.process.bind(t)
43
+ }
44
+
45
+ process(callback) {
46
+ let t = this, fname = "test_all.test3.process"
47
+ t.log({ msg: `This object (${fname}) is id (${t.id}). Do stuff here`.bgBrightGreen, type: "info" })
48
+ // callback({success: { msg: `processing all test3` }})
49
+ callback({ error: { msg: `there is some problem thrown here on test3` } })
50
+ }
51
+ }
52
+
53
+ var tst4 = class test4 {
54
+ constructor(props) {
55
+ let t = this, fname = "test_all.test4.constructor"
56
+ t.log = props.log
57
+ t.id = props.id
58
+
59
+ t.process = t.process.bind(t)
60
+ }
61
+
62
+ process(callback) {
63
+ let t = this, fname = "test_all.test4.process"
64
+ t.log({ msg: `This object (${fname}) is id (${t.id}). Do stuff here`.bgBrightGreen, type: "info" })
65
+ callback({ success: { msg: `processing all test4` } })
66
+ }
67
+ }
68
+
69
+ var lq = require("log-queue"),
70
+ log = new lq({
71
+ exclude_logMsg: ["debug"], /* example ["debug", "info"] */
72
+ }),
73
+ a_resolve, a_reject,
74
+ promise = new Promise((resolve, reject) => {
75
+ a_resolve = resolve
76
+ a_reject = reject
77
+ }),
78
+ bb = require("../app.js"),
79
+ base_queue = new bb({
80
+ parent: null,
81
+ relative_path: "./appenders/",
82
+ logMsg: log.logMsg,
83
+ resolve: a_resolve,
84
+ reject: a_reject
85
+ }).load({
86
+ appender: "all",
87
+ exclude_logMsg: ["debug"], /* example ["debug", "info"] */
88
+ process_objects: [tst1, tst2, tst3, tst4]
89
+ }).process()
90
+
91
+ promise.then((success) => {
92
+ log.logMsg({ msg: `All object processed successfully` })
93
+ }, (error) => {
94
+ if (typeof error == "string") {
95
+ log.logMsg({ msg: `error: ${error}`.error.italic.bold, type: "error" })
96
+ } else {
97
+ let add_s = (error.error_count > 1) ? 's' : ''
98
+ log.logMsg({ msg: `${error.error_count} error${add_s} detected`.error.italic.bold, type: "error" })
99
+ }
100
+ })
101
+