file-obj-queue 0.0.3

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 jman717
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,19 @@
1
+ An array of objects containing file path information. One use is for dynamically import require modules.
2
+
3
+ Installation
4
+ ---------
5
+
6
+ [![NPM](https://nodei.co/npm/file-queue.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/file-queue/)
7
+
8
+ Mocha Test
9
+ ---------
10
+ ```
11
+ npm test
12
+ ```
13
+
14
+ General Setup Test
15
+ ---------
16
+ ```
17
+ npm run test_files
18
+
19
+ ```
package/app.js ADDED
@@ -0,0 +1,107 @@
1
+ /* @author Jim Manton: jrman@risebroadband.net
2
+ * @since 2023-01-15
3
+ * Main processing app
4
+ */
5
+
6
+ var colors = require('colors'),
7
+ queue = require("queuejson"),
8
+ fs = require('fs');
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
+
30
+ do_checks() {
31
+ let t = this,
32
+ last_item = t.absolute_path.split("\\").pop(),
33
+ check_file = t.absolute_path.split(last_item)[0], check_path = t.path.split('/')
34
+
35
+ check_file = check_file.replace(/\\/g, "/");
36
+ check_path.map((dat, i) => {
37
+ if (/^[a-zA-Z._]+$/.test(dat)) {
38
+ if (dat != '.')
39
+ check_file += dat + '/'
40
+ }
41
+ })
42
+ check_file = check_file.slice(0, -1)
43
+ try {
44
+ if (!fs.existsSync(check_file)) {
45
+ t.errors = true
46
+ t.error_msg = `id = ${t.id} name(${t.name}) file (${check_file} does not exist)`
47
+ }
48
+ } catch (e) {
49
+ e.message = "file_obj do_checks error: " + e.message
50
+ throw (e)
51
+ }
52
+ }
53
+
54
+ process(callback) {
55
+ let t = this
56
+ if (t.errors)
57
+ callback({ error: { msg: t.error_msg } })
58
+ else
59
+ callback({ success: { msg: `id = ${t.id} name(${t.name})` } })
60
+ }
61
+ }
62
+
63
+ exports = module.exports = class FilesQueue {
64
+ constructor() {
65
+ try {
66
+ var t = this
67
+ // t.id = 0
68
+ // t.appenders_dir = './lib/appenders/'
69
+ // t.props = {}
70
+ t.logMsg = t.logMsg.bind(t)
71
+ t.init = t.init.bind(t)
72
+ t.getFileObject = t.getFileObject.bind(t)
73
+ return t
74
+ } catch (e) {
75
+ e.message = "FilesQueue app.js constructor error: " + e.message
76
+ throw (e)
77
+ }
78
+ }
79
+
80
+ init(props = {}) {
81
+ let t = this
82
+ try {
83
+ if (typeof props.input_data == 'undefined')
84
+ throw new Error('props.input_data is not defined')
85
+ t.qJson = new queue({
86
+ class_obj: file_obj,
87
+ appender: 'all',
88
+ stats: true,
89
+ debug: true
90
+ })
91
+ t.qJson.init({ input_data: props.input_data }).process()
92
+ return t
93
+ } catch (e) {
94
+ e.message = "FilesQueue app.js init error: " + e.message
95
+ t.logMsg(e.message)
96
+ throw (e)
97
+ }
98
+ }
99
+
100
+ getFileObject() {
101
+ return this.qJson.get_class_obj_array()
102
+ }
103
+
104
+ logMsg(msg, props = {}) {
105
+ console.log(msg)
106
+ }
107
+ }
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "author": {
3
+ "name": "Jim Manton"
4
+ },
5
+ "version": "0.0.3",
6
+ "bundleDependencies": false,
7
+ "dependencies": {
8
+ "chai": "^4.3.7",
9
+ "node-console-colors": "^1.1.4",
10
+ "queuejson": "^8.3.1",
11
+ "diffler": "^2.0.4",
12
+ "fs": "^0.0.1-security",
13
+ "mocha": "^10.2.0"
14
+ },
15
+ "scripts": {
16
+ "start": "node app.ts",
17
+ "test": "mocha",
18
+ "ditched": "ditched -a",
19
+ "test_files": "node ./tests/files"
20
+ },
21
+ "keywords": [
22
+ "queue",
23
+ "processing",
24
+ "appenders",
25
+ "javascript",
26
+ "synchronous",
27
+ "objects",
28
+ "promises",
29
+ "mocha"
30
+ ],
31
+ "homepage": "https://github.com/jman717/file-obj-queue",
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "git+https://github.com/jman717/file-obj-queue.git"
35
+ },
36
+ "deprecated": false,
37
+ "description": "Queue File Objects",
38
+ "email": "jrman@risebroadband.net",
39
+ "license": "MIT",
40
+ "main": "app.js",
41
+ "name": "file-obj-queue",
42
+ "start": "node app.js"
43
+ }
package/test/app.js ADDED
@@ -0,0 +1,38 @@
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())
9
+ })
10
+
11
+ it('app.init is a function', function () {
12
+ assert(typeof app.init == 'function')
13
+ })
14
+
15
+ it('app.logMsg is a function', function () {
16
+ assert(typeof app.logMsg == 'function')
17
+ })
18
+
19
+ it('app.getFileObject is a function', function () {
20
+ assert(typeof app.getFileObject == 'function')
21
+ })
22
+ })
23
+
24
+ describe('require', function () {
25
+
26
+
27
+ it('colors app', function () {
28
+ assert(require('colors'))
29
+ })
30
+
31
+ it('queuejson', function () {
32
+ assert(require('queuejson'))
33
+ })
34
+
35
+ it('fs', function () {
36
+ assert(require('fs'))
37
+ })
38
+ })
@@ -0,0 +1,59 @@
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.3",
10
+ "bundleDependencies": false,
11
+ "dependencies": {
12
+ "chai": "^4.3.7",
13
+ "node-console-colors": "^1.1.4",
14
+ "queuejson": "^8.3.1",
15
+ "diffler": "^2.0.4",
16
+ "fs": "^0.0.1-security",
17
+ "mocha": "^10.2.0"
18
+ },
19
+ "scripts": {
20
+ "start": "node app.ts",
21
+ "test": "mocha",
22
+ "ditched": "ditched -a",
23
+ "test_files": "node ./tests/files"
24
+ },
25
+ "keywords": [
26
+ "queue",
27
+ "processing",
28
+ "appenders",
29
+ "javascript",
30
+ "synchronous",
31
+ "objects",
32
+ "promises",
33
+ "mocha"
34
+ ],
35
+ "homepage": "https://github.com/jman717/file-obj-queue",
36
+ "repository": {
37
+ "type": "git",
38
+ "url": "git+https://github.com/jman717/file-obj-queue.git"
39
+ },
40
+ "deprecated": false,
41
+ "description": "Queue File Objects",
42
+ "email": "jrman@risebroadband.net",
43
+ "license": "MIT",
44
+ "main": "app.js",
45
+ "name": "file-obj-queue",
46
+ "start": "node app.js"
47
+ }
48
+
49
+ describe('package.json', function () {
50
+ it('should pass', function () {
51
+ const difference = jsonHasDifferences(packagejson, packageMock)
52
+ assert(JSON.stringify(difference) == "{}")
53
+ })
54
+
55
+ it('should fail', function () {
56
+ packageMock.version = '0'
57
+ assert(jsonHasDifferences(packagejson, packageMock))
58
+ })
59
+ })
@@ -0,0 +1,17 @@
1
+ /*
2
+ * @author Jim Manton: jrman@risebroadband.net
3
+ * @since 2021-03-22l
4
+ * lib/appenders/all.js
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
+ t.aname = 'all'
14
+ t.pro_types = ['items']
15
+ return t
16
+ }
17
+ }
@@ -0,0 +1,189 @@
1
+ /*
2
+ * @author Jim Manton: jrman@risebroadband.net
3
+ * @since 2017-10-01
4
+ * lib/appenders/base.js
5
+ */
6
+
7
+ var colors = require('colors')
8
+
9
+ class process_all_obj {
10
+ constructor(props) {
11
+ let t = this
12
+ t.parent = props.parent
13
+ t.objs = t.parent.getParent().getObjs()
14
+ t.status = 'process'
15
+ t.process_objs_item = 0
16
+ t.process_props_item = 0
17
+ t.await_item = 0
18
+ t.any_errors = false
19
+
20
+ t.continueProcessing = t.continueProcessing.bind(t)
21
+ }
22
+
23
+ process = () => {
24
+ let t = this
25
+ try {
26
+ if (t.process_objs_item >= t.objs.length) {
27
+ if (t.any_errors)
28
+ t.setStatus('finish with errors')
29
+ else
30
+ t.setStatus('finish')
31
+ return
32
+ }
33
+ try {
34
+ let obj, pro, itm
35
+ try {
36
+ obj = t.parent.getParent().getItemToProcess(t.process_objs_item)
37
+ } catch (e) {
38
+ e.message = `base error: (${e.message})`
39
+ throw e
40
+ }
41
+ try {
42
+ pro = (typeof obj == 'function') ? obj : obj.process;
43
+ } catch (e) {
44
+ t.parent.getParent()(`pro error: (${e.message})`.red)
45
+ throw e
46
+ }
47
+ if (typeof t.parent.pro_props != 'undefined' &&
48
+ typeof t.parent.pro_props.property != 'undefined' &&
49
+ typeof t.parent.pro_props.items != 'undefined' &&
50
+ typeof obj._getProperty == 'function') {
51
+ let skip = true
52
+ for (let q = 0; q < t.parent.pro_props.items.length; q++) {
53
+ itm = t.parent.pro_props.items[q]
54
+ if (itm == obj._getProperty(obj)) {
55
+ skip = false
56
+ break
57
+ }
58
+ }
59
+ if (skip) {
60
+ t.continueProcessing()
61
+ return
62
+ }
63
+ }
64
+ t.setStatus('wait')
65
+ pro((obj_props) => {
66
+ try {
67
+ if (typeof obj_props != 'undefined' && typeof obj_props.error != 'undefined') {
68
+ t.any_errors = true
69
+ t.parent.getParent().logMsg(obj_props)
70
+ } else {
71
+ t.parent.getParent().logMsg(obj_props)
72
+ }
73
+ t.parent.results_array.push(obj_props)
74
+ t.continueProcessing()
75
+ } catch (e) {
76
+ t.parent.getParent().logMsg(`pro obj error: (${e.message})`.red)
77
+ throw e
78
+ }
79
+ })
80
+ } catch (e) {
81
+ e.message = `error: ${e.message} `
82
+ throw e
83
+ }
84
+ } catch (e) {
85
+ e.message = `process_all_obj error: ${e.message} `
86
+ throw e
87
+ }
88
+ }
89
+
90
+ continueProcessing = () => {
91
+ let t = this
92
+ t.process_objs_item++
93
+ t.setStatus('process')
94
+ t.parent.process_all()
95
+ }
96
+
97
+ getStatus = () => {
98
+ return this.status
99
+ }
100
+
101
+ setStatus = (v) => {
102
+ this.status = v
103
+ }
104
+ }
105
+
106
+ exports = module.exports = class base {
107
+ constructor(props) {
108
+ let t = this
109
+ t.await_array = []
110
+ t.resolve_array = []
111
+ t.reject_array = []
112
+ t.results_array = []
113
+ t.getParent = props.getParent
114
+ t.dt_start = null
115
+ t.dt_end = null
116
+ t.process_all_obj = null
117
+ t.pro_props = []
118
+
119
+ t.process = t.process.bind(this)
120
+ t.process_all = t.process_all.bind(this)
121
+ }
122
+
123
+ // await(props) {
124
+ // let t = this
125
+ // t.await_array.push(props)
126
+ // return new Promise((resolve, reject) => {
127
+ // t.resolve_array.push(resolve)
128
+ // t.reject_array.push(reject)
129
+ // });
130
+ // }
131
+
132
+ process(props) {
133
+ let t = this
134
+ t.dt_start = new Date(); // start measuring time
135
+
136
+ t.pro_props = props
137
+
138
+ return new Promise((resolve, reject) => {
139
+ t.resolve_array.push(resolve)
140
+ t.reject_array.push(reject)
141
+ t.process_all()
142
+ });
143
+ }
144
+
145
+ getStats() {
146
+ let t = this
147
+ t.dt_end = new Date();
148
+ let ret_str = '', st = t.dt_start, ed = t.dt_end, ml = t.dt_end - t.dt_start
149
+ // ret_str += JSON.stringify(t.results_array)
150
+ if (t.getParent().getStats()) {
151
+ ret_str += `start (${st}) end(${ed}) milliseconds(${ml})`
152
+ }
153
+ return ret_str
154
+ }
155
+
156
+ process_all = () => {
157
+ let t = this, _continue
158
+ if (t.process_all_obj == null) {
159
+ t.process_all_obj = new process_all_obj({ parent: t })
160
+ }
161
+
162
+ _continue = false
163
+ try {
164
+ switch (t.process_all_obj.getStatus()) {
165
+ case 'process':
166
+ t.process_all_obj.process()
167
+ _continue = true
168
+ break
169
+ case 'finish with errors':
170
+ t.reject_array[t.reject_array.length - 1](t.getStats())
171
+ break
172
+ case 'finish':
173
+ t.resolve_array[t.resolve_array.length - 1](t.getStats())
174
+ break
175
+ case 'wait':
176
+ return
177
+ default:
178
+ throw new Error(`status(${t.process_all_obj.getStatus()}) does not exist`)
179
+ }
180
+
181
+ if (_continue)
182
+ t.process_all()
183
+ } catch (e) {
184
+ e.message = `process_all error: ${e.message} `
185
+ throw e
186
+ }
187
+ }
188
+ }
189
+
@@ -0,0 +1,17 @@
1
+ /*
2
+ * @author Jim Manton: jrman@risebroadband.net
3
+ * @since 2021-03-22
4
+ * lib/appenders/bottom_one.js
5
+ */
6
+
7
+ var base = require('./base.js')
8
+
9
+ exports = module.exports = class bottom_one extends base{
10
+ constructor(props) {
11
+ super(props)
12
+ var t = this
13
+ t.aname = 'bottom_one'
14
+ t.pro_types = ['items']
15
+ return t
16
+ }
17
+ }
@@ -0,0 +1,17 @@
1
+ /*
2
+ * @author Jim Manton: jrman@risebroadband.net
3
+ * @since 2021-03-22
4
+ * lib/appenders/func_all.js
5
+ */
6
+
7
+ var base = require('./base.js')
8
+
9
+ exports = module.exports = class func_all extends base {
10
+ constructor(props) {
11
+ super(props)
12
+ var t = this
13
+ t.aname = 'func_all'
14
+ t.pro_types = ['items']
15
+ return t
16
+ }
17
+ }
@@ -0,0 +1,17 @@
1
+ /*
2
+ * @author Jim Manton: jrman@risebroadband.net
3
+ * @since 2023-01-16
4
+ * lib/appenders/name.js
5
+ */
6
+
7
+ var base = require('./base.js')
8
+
9
+ exports = module.exports = class name extends base {
10
+ constructor(props) {
11
+ super(props)
12
+ var t = this
13
+ t.aname = 'name'
14
+ t.pro_types = ['name']
15
+ return t
16
+ }
17
+ }
@@ -0,0 +1,17 @@
1
+ /*
2
+ * @author Jim Manton: jrman@risebroadband.net
3
+ * @since 2023-01-16
4
+ * lib/appenders/status.js
5
+ */
6
+
7
+ var base = require('./base.js')
8
+
9
+ exports = module.exports = class status extends base {
10
+ constructor(props) {
11
+ super(props)
12
+ var t = this
13
+ t.aname = 'status'
14
+ t.pro_types = ['status']
15
+ return t
16
+ }
17
+ }
@@ -0,0 +1,17 @@
1
+ /*
2
+ * @author Jim Manton: jrman@risebroadband.net
3
+ * @since 2021-03-22
4
+ * lib/appenders/sync.js
5
+ */
6
+
7
+ var base = require('./base.js')
8
+
9
+ exports = module.exports = class sync extends base {
10
+ constructor(props) {
11
+ super(props)
12
+ var t = this
13
+ t.aname = 'sync'
14
+ t.pro_types = ['items', 'byIds']
15
+ return t
16
+ }
17
+ }
@@ -0,0 +1,17 @@
1
+ /*
2
+ * @author Jim Manton: jrman@risebroadband.net
3
+ * @since 2021-03-22
4
+ * lib/appenders/sync_all.js
5
+ */
6
+
7
+ var base = require('./base.js')
8
+
9
+ exports = module.exports = class sync_all extends base {
10
+ constructor(props) {
11
+ super(props)
12
+ var t = this
13
+ t.aname = 'sync_all'
14
+ t.pro_types = ['items']
15
+ return t
16
+ }
17
+ }
@@ -0,0 +1,17 @@
1
+ /*
2
+ * @author Jim Manton: jrman@risebroadband.net
3
+ * @since 2021-03-22
4
+ * lib/appenders/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
13
+ t.aname = 'top_one'
14
+ t.pro_types = ['items']
15
+ return t
16
+ }
17
+ }
@@ -0,0 +1,17 @@
1
+ /*
2
+ * @author Jim Manton: jrman@risebroadband.net
3
+ * @since 2021-03-22
4
+ * lib/appenders/status.js
5
+ */
6
+
7
+ var base = require('./base.js')
8
+
9
+ exports = module.exports = class version extends base {
10
+ constructor(props) {
11
+ super(props)
12
+ var t = this
13
+ t.aname = 'version'
14
+ t.pro_types = ['version']
15
+ return t
16
+ }
17
+ }
package/tests/files.js ADDED
@@ -0,0 +1,18 @@
1
+ var colors = require('colors'),
2
+ file_queue = require("../app.js")
3
+
4
+ var file_data = [
5
+ { props: { id: 100, name: "all", path: "./appenders/all.js", absolute_path: __filename, check: true } },
6
+ { props: { id: 101, name: "func_all", path: "./appenders/func_all.js", absolute_path: __filename, check: true } },
7
+ { props: { id: 102, name: "top_one", path: "./appenders/top_one.js", absolute_path: __filename, check: true } },
8
+ { props: { id: 103, name: "bottom_one", path: "./appenders/bottom_one.js", absolute_path: __filename, check: true } },
9
+ { props: { id: 104, name: "sync_all", path: "./appenders/sync_all.js", absolute_path: __filename, check: true } },
10
+ { props: { id: 105, name: "status", path: "./appenders/status.js", absolute_path: __filename, check: true } },
11
+ { props: { id: 106, name: "name", path: "./appenders/name.js", absolute_path: __filename, check: true } },
12
+ { props: { id: 107, name: "version", path: "./appenders/version.js", absolute_path: __filename, check: true } }
13
+ ]
14
+
15
+ var qRequire = new file_queue().init({ input_data: file_data })
16
+
17
+ console.log(`test complete`.blue)
18
+