qtools-library-dot-d 1.0.7 → 1.0.9

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 (74) hide show
  1. package/README.md +19 -25
  2. package/libDotD_Working_Example/README.md +234 -0
  3. package/libDotD_Working_Example/demoModules_DotD/demo1.js +46 -0
  4. package/libDotD_Working_Example/demoModules_DotD/demo2.js +48 -0
  5. package/libDotD_Working_Example/index.js +133 -0
  6. package/libDotD_Working_Example/node_modules/.package-lock.json +29 -0
  7. package/libDotD_Working_Example/node_modules/qtools-asynchronous-pipe-plus/README.md +213 -0
  8. package/libDotD_Working_Example/node_modules/qtools-asynchronous-pipe-plus/package.json +20 -0
  9. package/libDotD_Working_Example/node_modules/qtools-asynchronous-pipe-plus/qtools-asynchronous-pipe-plus.js +278 -0
  10. package/libDotD_Working_Example/node_modules/qtools-asynchronous-pipe-plus/test.js +79 -0
  11. package/libDotD_Working_Example/node_modules/qtools-functional-library/README.md +110 -0
  12. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-clone/package.json +11 -0
  13. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-clone/qtools-clone.js +103 -0
  14. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-clone/test.js +78 -0
  15. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-get-by-property/package.json +11 -0
  16. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-get-by-property/qtools-get-by-property.js +73 -0
  17. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-get-by-property/test.js +129 -0
  18. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-includes-regex/package.json +11 -0
  19. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-includes-regex/qtools-includes-regex.js +54 -0
  20. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-includes-regex/test.js +76 -0
  21. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-log-output/package.json +11 -0
  22. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-log-output/qtools-log-output.js +114 -0
  23. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-log-output/test.js +130 -0
  24. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-map-properties/package.json +11 -0
  25. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-map-properties/qtools-map-properties.js +99 -0
  26. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-map-properties/test.js +118 -0
  27. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-merge/package.json +11 -0
  28. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-merge/qtools-merge.js +147 -0
  29. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-merge/test.js +214 -0
  30. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-new-method-template/package.json +11 -0
  31. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-new-method-template/qtools-new-method-template.js +70 -0
  32. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-new-method-template/test.js +66 -0
  33. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-number-iterator/package.json +11 -0
  34. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-number-iterator/qtools-number-iterator.js +137 -0
  35. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-number-iterator/test.js +68 -0
  36. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-number-keys-to-array/package.json +11 -0
  37. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-number-keys-to-array/qtools-number-keys-to-array.js +131 -0
  38. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-number-keys-to-array/test.js +181 -0
  39. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-object-sure-path/package.json +11 -0
  40. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-object-sure-path/qtools-object-sure-path.js +204 -0
  41. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-object-sure-path/test.js +345 -0
  42. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-pass-through/package.json +11 -0
  43. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-pass-through/qtools-pass-through.js +58 -0
  44. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-pass-through/test.js +66 -0
  45. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-pop/package.json +11 -0
  46. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-pop/qtools-pop.js +175 -0
  47. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-pop/test.js +118 -0
  48. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-print-debug/package.json +11 -0
  49. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-print-debug/qtools-print-debug.js +352 -0
  50. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-print-debug/test.js +77 -0
  51. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-select-properties/package.json +11 -0
  52. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-select-properties/qtools-select-properties.js +132 -0
  53. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-select-properties/test.js +156 -0
  54. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-template-replace/README.md +3 -0
  55. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-template-replace/package.json +11 -0
  56. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-template-replace/qtools-template-replace.js +106 -0
  57. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-template-replace/test.js +168 -0
  58. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-to-key-value-array/package.json +11 -0
  59. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-to-key-value-array/qtools-to-key-value-array.js +83 -0
  60. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-to-key-value-array/test.js +68 -0
  61. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-to-string/package.json +11 -0
  62. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-to-string/qtools-to-string.js +84 -0
  63. package/libDotD_Working_Example/node_modules/qtools-functional-library/lib/qtools-to-string/test.js +63 -0
  64. package/libDotD_Working_Example/node_modules/qtools-functional-library/package.json +37 -0
  65. package/libDotD_Working_Example/node_modules/qtools-functional-library/qtFunctionalDemo.js +297 -0
  66. package/libDotD_Working_Example/node_modules/qtools-functional-library/qtools-functional-library.js +271 -0
  67. package/libDotD_Working_Example/node_modules/qtools-functional-library/test.js +47 -0
  68. package/libDotD_Working_Example/node_modules/qtools-library-dot-d/README.md +208 -0
  69. package/libDotD_Working_Example/node_modules/qtools-library-dot-d/package.json +15 -0
  70. package/libDotD_Working_Example/node_modules/qtools-library-dot-d/qtools-library-dot-d.js +239 -0
  71. package/libDotD_Working_Example/package-lock.json +37 -0
  72. package/libDotD_Working_Example/package.json +23 -0
  73. package/package.json +1 -1
  74. package/qtools-library-dot-d.js +2 -2
@@ -0,0 +1,239 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ const moduleName = __filename.replace(__dirname + '/', '').replace(/.js$/, ''); //this just seems to come in handy a lot
5
+
6
+ // const qt = require('qtools-functional-library'); //also exposes qtLog(); qt.help({printOutput:true, queryString:'.*', sendJson:false});
7
+
8
+ const os = require('os');
9
+ const path = require('path');
10
+ const fs = require('fs');
11
+
12
+ const qt = require('qtools-functional-library');
13
+
14
+ //START OF moduleFunction() ============================================================
15
+ const moduleFunction =
16
+ ({ moduleName } = {}) =>
17
+ ({ libraryName='libraryDotD' }) => {
18
+ // ======================================================================================
19
+ // SETTERS
20
+
21
+ // --------------------------------------------------------------------------------
22
+ // SET LIBRARY PATH
23
+
24
+ let libraryPath;
25
+
26
+ const setLibraryPath = (dirPath, callback) => {
27
+ try {
28
+ libraryPath = fs.realpathSync(dirPath);
29
+ } catch (err) {
30
+ callback(err.toString());
31
+ return;
32
+ }
33
+
34
+ if (typeof callback == 'function') {
35
+ callback('', libraryPath);
36
+ } else {
37
+ return libraryPath;
38
+ }
39
+ };
40
+
41
+ // --------------------------------------------------------------------------------
42
+ // SET CUSTOM MODULE ADDING FUNCTION
43
+
44
+ const defaultAdd = (item, callback) => {
45
+ let error;
46
+ try {
47
+ require(item.endpointPath)(item.moduleArgs); //calls module with dotD object, including library.add()
48
+ } catch (err) {
49
+ item.exceptionList.push(
50
+ `${path.basename(item.endpointPath)}: ${err.toString().split('\n').qtFirst('n/a')}`,
51
+ );
52
+ }
53
+
54
+ if (typeof callback == 'function') {
55
+ callback(error);
56
+ } else {
57
+ return;
58
+ }
59
+ };
60
+
61
+ let add = defaultAdd;
62
+
63
+ const setCustomAddFunction = (newFunction) => (add = newFunction);
64
+
65
+ // ======================================================================================
66
+ // LOG LIST OBJECT
67
+
68
+ const logList = (() => {
69
+ const list = [];
70
+ const push = (item) => list.push(item);
71
+ const formatList = () => {
72
+ return list
73
+ .reduce(
74
+ (result, item) => `${result}${item}\n\t`,
75
+ `\n${libraryName} Log\n\t`,
76
+ )
77
+ .replace(/\n\t$/, '');
78
+ };
79
+ return { push, formatList };
80
+ })();
81
+
82
+ // ======================================================================================
83
+ // LIBRARY OBJECT
84
+
85
+ const libraryObject = {}; //used only for producing display listings
86
+ const exceptionList = [];
87
+ const library = (() => {
88
+ const add = (name, item) => {
89
+ libraryObject[name] = item; //used only for producing display listings
90
+ externalElements[name] = item;
91
+ };
92
+ return { add };
93
+ })();
94
+
95
+ // ======================================================================================
96
+ // LIBRARY OBJECT
97
+
98
+ const toString = () => {
99
+ const formatProperty = (item) => {
100
+ let outString = typeof item;
101
+ if (typeof item == 'function') {
102
+ const result = item.toString().match(/\((?<args>.*?\))/);
103
+ const args = result.qtGetSurePath('groups.args', 'function');
104
+ outString = `(${args == ')' ? args + ' # function takes no arguments' : args}`;
105
+ }
106
+ return outString;
107
+ };
108
+
109
+ const libString = Object.keys(libraryObject)
110
+ .reduce(
111
+ (result, name) =>
112
+ `${result}${name}: ${
113
+ (typeof libraryObject[name]).match(/(string|number)/i)
114
+ ? libraryObject[name]
115
+ : formatProperty(libraryObject[name])
116
+ }\n\t`,
117
+ `\n${libraryName} Library Elements\n\t`,
118
+ )
119
+ .replace(/\n\t$/, '');
120
+
121
+ const exceptionString = '\n\t' + exceptionList.join('\n\t');
122
+
123
+ return `${libString}${exceptionString}`;
124
+ };
125
+
126
+ // ======================================================================================
127
+ // SEAL OBJECT (make immutable)
128
+
129
+ const sealActual = (externalElements) => () => {
130
+ Object.assign(
131
+ externalElements.library.qtSelectProperties(['add'], {
132
+ excludeMode: true,
133
+ }),
134
+ );
135
+ Object.assign(
136
+ externalElements.logList.qtSelectProperties(['push'], {
137
+ excludeMode: true,
138
+ }),
139
+ );
140
+
141
+ Object.assign(
142
+ externalElements.qtSelectProperties(
143
+ [
144
+ 'setLibraryPath',
145
+ 'loadModules',
146
+ 'seal',
147
+ 'setCustomAddFunction',
148
+ 'library',
149
+ 'logList',
150
+ ],
151
+ { excludeMode: true },
152
+ ),
153
+ );
154
+ Object.freeze(externalElements);
155
+ Object.seal(externalElements);
156
+ };
157
+
158
+ // ======================================================================================
159
+ // LOAD MODULES (actual execution)
160
+
161
+ const loadModules = ({ passThroughParameters }, callback) => {
162
+ const asynchronousPipePlus = new require(
163
+ 'qtools-asynchronous-pipe-plus',
164
+ )();
165
+ const pipeRunner = asynchronousPipePlus.pipeRunner;
166
+ const taskListPlus = asynchronousPipePlus.taskListPlus;
167
+
168
+ const taskList = new taskListPlus();
169
+
170
+ // --------------------------------------------------------------------------------
171
+ // INTERNAL UTILITIES
172
+
173
+ const mergeArgs = (args, next, propertyName) => (err, result) =>
174
+ next(err, {
175
+ ...args,
176
+ ...(propertyName ? { [propertyName]: result } : result),
177
+ });
178
+
179
+ const forwardArgs =
180
+ ({ next, args }) =>
181
+ (err) =>
182
+ next(err, args);
183
+
184
+ // --------------------------------------------------------------------------------
185
+ // INITIALIZE COMMON ADDED MODULE PARAMETERS
186
+
187
+ const dotD = { logList, library };
188
+
189
+ const moduleArgs = {
190
+ dotD,
191
+ passThroughParameters,
192
+ };
193
+
194
+ fs.readdirSync(libraryPath)
195
+ //.filter(file => path.extname(file) === '.js')
196
+ .forEach((file) => {
197
+ const endpointPath = path.join(libraryPath, file);
198
+
199
+ add({
200
+ endpointPath,
201
+ moduleArgs,
202
+ exceptionList,
203
+ });
204
+ });
205
+
206
+ // --------------------------------------------------------------------------------
207
+ // INIT AND EXECUTE THE PIPELINE
208
+
209
+ if (typeof callback == 'function') {
210
+ if (exceptionList.length) {
211
+ callback(exceptionList);
212
+ } else {
213
+ callback();
214
+ }
215
+ } else {
216
+ if (exceptionList.length) {
217
+ return exceptionList;
218
+ } else {
219
+ return;
220
+ }}
221
+ };
222
+
223
+ const externalElements = {
224
+ setLibraryPath,
225
+ setCustomAddFunction,
226
+ logList,
227
+ library,
228
+ loadModules,
229
+ toString,
230
+ qtdProcessLog: logList.formatList,
231
+ };
232
+ externalElements.seal = sealActual(externalElements);
233
+ return externalElements;
234
+ };
235
+
236
+ //END OF moduleFunction() ============================================================
237
+
238
+ module.exports = moduleFunction({ moduleName });
239
+
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "libdotd_example",
3
+ "version": "1.0.0",
4
+ "lockfileVersion": 3,
5
+ "requires": true,
6
+ "packages": {
7
+ "": {
8
+ "name": "libdotd_example",
9
+ "version": "1.0.0",
10
+ "license": "ISC",
11
+ "dependencies": {
12
+ "qtools-library-dot-d": "^1.0.5"
13
+ }
14
+ },
15
+ "node_modules/qtools-asynchronous-pipe-plus": {
16
+ "version": "1.0.5",
17
+ "resolved": "https://registry.npmjs.org/qtools-asynchronous-pipe-plus/-/qtools-asynchronous-pipe-plus-1.0.5.tgz",
18
+ "integrity": "sha512-ejueK++dNl6AJL0OK14zTewXDg1+Wq8zFknI83THmgR9rNTB7EfngLt031/hkkc3/VpnqdaeO7mNqnu6YAzgIQ=="
19
+ },
20
+ "node_modules/qtools-functional-library": {
21
+ "version": "2.0.4",
22
+ "resolved": "https://registry.npmjs.org/qtools-functional-library/-/qtools-functional-library-2.0.4.tgz",
23
+ "integrity": "sha512-noztSkJI37xcOTer5HVgOnuY/eZ1FeqtSvlpzhmSq7jjT6dQCQjIzwjoe1GqHc5Dt9Os+OFawAUz3hMpO4V1ng==",
24
+ "license": "ISC"
25
+ },
26
+ "node_modules/qtools-library-dot-d": {
27
+ "version": "1.0.5",
28
+ "resolved": "https://registry.npmjs.org/qtools-library-dot-d/-/qtools-library-dot-d-1.0.5.tgz",
29
+ "integrity": "sha512-MEkrc1NCk8OleAlUPrlJ4Pl8z9v4gOEQt6PIjTc7r16x4StnfQ/ntTfaFF2kS4pi6O1zY1YBpB8vG1q0rdwTcQ==",
30
+ "license": "ISC",
31
+ "dependencies": {
32
+ "qtools-asynchronous-pipe-plus": "^1.0.2",
33
+ "qtools-functional-library": "^2.0.4"
34
+ }
35
+ }
36
+ }
37
+ }
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "libdotd_example",
3
+ "version": "1.0.0",
4
+ "description": "Boilerplate for use of qtools-library-dot-d - demonstrates dynamic module loading",
5
+ "license": "ISC",
6
+ "author": "TQ White II",
7
+ "type": "commonjs",
8
+ "main": "index.js",
9
+ "scripts": {
10
+ "test": "echo \"Error: no test specified\" && exit 1",
11
+ "start": "node index.js"
12
+ },
13
+ "dependencies": {
14
+ "_comment_qtools-library-dot-d": "Core library for dynamic dotD module loading - provides qtLibDotD factory function",
15
+ "qtools-library-dot-d": "^1.0.5"
16
+ },
17
+ "_instructions": {
18
+ "usage": "Run 'npm start' to see both synchronous and asynchronous dotD library demos",
19
+ "creating_new_modules": "Add .js files to the demoModules_DotD directory - they'll automatically become library methods",
20
+ "module_naming": "Filename determines method name: 'myModule.js' becomes 'libraryInstance.myModule()'",
21
+ "shared_resources": "Use passThroughParameters in index.js to share config, utilities, database connections, etc. across all modules"
22
+ }
23
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qtools-library-dot-d",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "Scan a directory for JS modules that can execute and addMe() that attaches it to some form of name/value list, eg, a Map() with functions as values or an xPressJS route/endpoint list.",
5
5
  "main": "qtools-library-dot-d.js",
6
6
  "scripts": {
@@ -14,7 +14,7 @@ const qt = require('qtools-functional-library');
14
14
  //START OF moduleFunction() ============================================================
15
15
  const moduleFunction =
16
16
  ({ moduleName } = {}) =>
17
- ({ libraryName }) => {
17
+ ({ libraryName='libraryDotD' }) => {
18
18
  // ======================================================================================
19
19
  // SETTERS
20
20
 
@@ -27,7 +27,7 @@ const moduleFunction =
27
27
  try {
28
28
  libraryPath = fs.realpathSync(dirPath);
29
29
  } catch (err) {
30
- callback(err.toString());
30
+ throw err.toString();
31
31
  return;
32
32
  }
33
33