binhend 2.2.3 → 2.2.4

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/index.js CHANGED
@@ -14,11 +14,16 @@ const { cors, trycatch } = require('./packages/middlewares');
14
14
 
15
15
  const { HTTPS } = require('./packages/https');
16
16
 
17
- const { config, ConfigLoader } = require('./packages/config');
17
+ const { config, ConfigLoader } = require('./packages/config/src/configuration');
18
18
 
19
19
  const { WebBuild, binh } = require('./packages/web');
20
20
 
21
- const { create: CSD, Controller: CinCSD, Service: SinCSD, DAO: DinCSD } = require('./packages/csd');
21
+ // const { create: CSD, Controller: CinCSD, Service: SinCSD, DAO: DinCSD } = require('./packages/csd/src/');
22
+
23
+ const CSD = require('./packages/csd/src/csd');
24
+ const CinCSD = require('./packages/csd/src/controller');
25
+ const SinCSD = require('./packages/csd/src/service');
26
+ const DinCSD = require('./packages/csd/src/dao');
22
27
 
23
28
  const { crypto } = require('./packages/crypto');
24
29
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "binhend",
3
- "version": "2.2.3",
3
+ "version": "2.2.4",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "author": "Nguyen Duc Binh",
@@ -1,145 +1,3 @@
1
-
2
- const fs = require('fs');
3
- const path = require('path');
4
- const { isEmptyArray, isArray, isObject, mustString, isNullish, isString } = require('@binhend/types');
5
-
6
- // @ts-ignore
7
- function ConfigLoader(configObject, { rootPath } = {}) {
8
- const configs = configObject || {};
9
-
10
- rootPath = mustString(rootPath) || require.main.path;
11
-
12
- function getConfigPosition(key) {
13
- return key == undefined ? configs : configs[key] || (configs[key] = {});
14
- };
15
-
16
- // @ts-ignore
17
- this.object = (object, { key, filter: filters, overwrite, use } = {}) => {
18
- let config = getConfigPosition(key);
19
- let filtered = isArray(filters) ? filter(object, filters) : object;
20
-
21
- remap(object, use);
22
- assign(config, filtered, overwrite);
23
-
24
- return this;
25
- };
26
-
27
- this.cli = (options) => {
28
- return this.object(cli(), options);
29
- };
30
-
31
- this.file = (filepath, options) => {
32
- let filePath = path.resolve(rootPath, filepath);
33
- return this.object(file(filePath, options?.encoding), options);
34
- };
35
- }
36
-
37
- ConfigLoader.cli = cli;
38
- ConfigLoader.file = file;
39
- ConfigLoader.require = require.main.require;
40
-
41
- function filter(object, filterKeys) {
42
- if (!isObject(object) || isEmptyArray(filterKeys)) return {};
43
-
44
- var filtered = {};
45
-
46
- filterKeys.forEach((field) => {
47
- if (object.hasOwnProperty(field)) {
48
- filtered[field] = object[field];
49
- }
50
- });
51
-
52
- return filtered;
1
+ module.exports = {
2
+ ...require('./src/configuration'),
53
3
  };
54
-
55
- function assign(config, filtered, overwrite) {
56
- if (overwrite !== false) {
57
- Object.assign(config, filtered);
58
- }
59
- else for (var key in filtered) {
60
- if (isNullish(config[key])) {
61
- config[key] = filtered[key];
62
- }
63
- }
64
- return config;
65
- };
66
-
67
- function remap(object, use) {
68
- if (!isString(use)) return object;
69
-
70
- for (var key in object) {
71
- const value = object[key];
72
- const hasValue = isObject(value) && value.hasOwnProperty(use);
73
- if (hasValue) object[key] = value[use];
74
- // else if value is not an object or has no "env" key, then the desired value is itself => no new assignment
75
- }
76
-
77
- return object;
78
- };
79
-
80
- function cli() {
81
- return processKeyValueStrings(process.argv);
82
- }
83
-
84
- function file(filepath, encoding) {
85
- encoding = encoding || 'utf8';
86
-
87
- try {
88
- var fileExtension = path.parse(filepath).ext;
89
-
90
- switch (fileExtension) {
91
- case '.js':
92
- case '.json':
93
- return ConfigLoader.require(filepath);
94
-
95
- default:
96
- var source = fs.readFileSync(filepath, { encoding });
97
- // @ts-ignore
98
- source = source.replace(/\r\n?/mg, '\n');
99
- // @ts-ignore
100
- var lines = source.split('\n');
101
-
102
- return processKeyValueStrings(lines);
103
- }
104
- }
105
- catch (error) {
106
- console.log(`[BINHEND] Failed loading config from: ${filepath}`);
107
- console.log('[BINHEND] Details:', error);
108
- return {};
109
- }
110
- }
111
-
112
- function processKeyValueStrings(strings) {
113
- var output = {};
114
-
115
- if (strings == undefined || !strings.length) {
116
- return output;
117
- }
118
-
119
- var regex_is_comment = /^#/;
120
-
121
- strings.forEach(function (string) {
122
- if (regex_is_comment.test(string.trim())) return;
123
-
124
- var parsed = parseKeyValue(string);
125
- if (parsed.success) {
126
- output[parsed.key] = parsed.value;
127
- }
128
- });
129
-
130
- return output;
131
- }
132
-
133
- function parseKeyValue(string) {
134
- var delimiter = '=';
135
-
136
- var parts = string.split(delimiter);
137
- if (parts.length < 2) return { success: false };
138
-
139
- var key = parts[0];
140
- var value = parts.splice(1).join(delimiter);
141
-
142
- return { key, value, success: true };
143
- }
144
-
145
- module.exports = { ConfigLoader, config: {} };