chain-simple 1.3.0 → 1.3.2
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/built/index.js +19 -7
- package/built/logger.d.ts +2 -8
- package/built/logger.js +1 -1
- package/lib/index.ts +26 -7
- package/lib/logger.ts +1 -1
- package/package.json +2 -2
package/built/index.js
CHANGED
|
@@ -36,6 +36,7 @@ logger_1.logger.setLogLevel(process.env.CHAIN_SIMPLE_LOG_LEVEL);
|
|
|
36
36
|
* @returns {object} object with chainable properties
|
|
37
37
|
*/
|
|
38
38
|
function makePropertiesChainable(item, config) {
|
|
39
|
+
const promiseCallableProps = ['then', 'catch', 'finally'];
|
|
39
40
|
const propsList = [];
|
|
40
41
|
if ((0, sat_utils_1.isObject)(config) && config.getEntityPropList) {
|
|
41
42
|
if (!(0, sat_utils_1.isObject)(config.getEntityPropList) && !(0, sat_utils_1.isArray)(config.getEntityPropList)) {
|
|
@@ -78,8 +79,7 @@ function makePropertiesChainable(item, config) {
|
|
|
78
79
|
return proxifiedResult;
|
|
79
80
|
};
|
|
80
81
|
}
|
|
81
|
-
if (p
|
|
82
|
-
p !== 'catch' &&
|
|
82
|
+
if (!promiseCallableProps.includes(p) &&
|
|
83
83
|
(0, sat_utils_1.isUndefined)(Reflect.get(item, p, r)) &&
|
|
84
84
|
(0, sat_utils_1.isObject)(config) &&
|
|
85
85
|
(0, sat_utils_1.isFunction)(config.extendProxed)) {
|
|
@@ -100,20 +100,32 @@ function makePropertiesChainable(item, config) {
|
|
|
100
100
|
}
|
|
101
101
|
const isCallable = (0, sat_utils_1.isFunction)(Reflect.get(item, p, r)) || (0, sat_utils_1.isAsyncFunction)(Reflect.get(item, p, r));
|
|
102
102
|
if (!isCallable && !(0, sat_utils_1.isPromise)(proxifiedResult) && item[p] && !proxifiedResult[p]) {
|
|
103
|
-
logger_1.logger.
|
|
103
|
+
logger_1.logger.chainer(`[CHAIN_SIMPLE]: ${String(p)} is not a callable.`);
|
|
104
104
|
return item[p];
|
|
105
105
|
}
|
|
106
106
|
else if (isCallable) {
|
|
107
|
+
logger_1.logger.chainer(`[CHAIN_SIMPLE]: ${String(p)} is a callable.`);
|
|
107
108
|
return function (...arguments_) {
|
|
108
|
-
|
|
109
|
-
|
|
109
|
+
logger_1.logger.chainer(`[CHAIN_SIMPLE]: ${String(p)} is called with args: `, ...arguments);
|
|
110
|
+
if ((0, sat_utils_1.isPromise)(proxifiedResult)) {
|
|
111
|
+
logger_1.logger.chainer(`[CHAIN_SIMPLE]: previous call result is a promise`);
|
|
112
|
+
proxifiedResult = proxifiedResult
|
|
113
|
+
.then(function (r) {
|
|
114
|
+
logger_1.logger.chainer(`[CHAIN_SIMPLE]: previous call result is: `, r);
|
|
110
115
|
return item[p].call(item, ...arguments_);
|
|
111
116
|
})
|
|
112
|
-
|
|
117
|
+
.catch(e => console.log(e));
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
logger_1.logger.chainer(`[CHAIN_SIMPLE]: previous call result is not a promise`);
|
|
121
|
+
logger_1.logger.chainer(`[CHAIN_SIMPLE]: previous call result is: `, proxifiedResult);
|
|
122
|
+
proxifiedResult = item[p].call(item, ...arguments_);
|
|
123
|
+
}
|
|
113
124
|
return proxed;
|
|
114
125
|
};
|
|
115
126
|
}
|
|
116
|
-
else if ((p
|
|
127
|
+
else if (promiseCallableProps.includes(p) && (0, sat_utils_1.isPromise)(proxifiedResult)) {
|
|
128
|
+
logger_1.logger.chainer(`[CHAIN_SIMPLE]: previous call result is a promise and next call is a promise method call`);
|
|
117
129
|
if (!(0, sat_utils_1.isPromise)(proxifiedResult)) {
|
|
118
130
|
return proxifiedResult;
|
|
119
131
|
}
|
package/built/logger.d.ts
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
declare const logger: {
|
|
2
|
-
|
|
3
|
-
log(...args: any[]): void;
|
|
4
|
-
info(...args: any[]): void;
|
|
5
|
-
warn(...args: any[]): void;
|
|
6
|
-
error(...args: any[]): void;
|
|
7
|
-
setLogLevel(level: string): void;
|
|
8
|
-
addCustomLevel(loggerDescription: any, logLevel: string, description: string, consoleOutput: string, descriptionColor: string, messageColor: any): void;
|
|
1
|
+
declare const logger: import("sat-utils").Tlogger & {
|
|
2
|
+
chainer: (...args: any[]) => void;
|
|
9
3
|
};
|
|
10
4
|
export { logger };
|
package/built/logger.js
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.logger = void 0;
|
|
4
4
|
const sat_utils_1 = require("sat-utils");
|
|
5
|
-
const logger = (0, sat_utils_1.createLogger)();
|
|
5
|
+
const logger = (0, sat_utils_1.createLogger)().addCustomLevel('chainer', 'CHAIN_LOG', 'CHAIN_LOG', 'info', 'BgBlue', 'BgWhite');
|
|
6
6
|
exports.logger = logger;
|
|
7
7
|
//# sourceMappingURL=logger.js.map
|
package/lib/index.ts
CHANGED
|
@@ -50,7 +50,9 @@ type TConfig = {
|
|
|
50
50
|
* @returns {object} object with chainable properties
|
|
51
51
|
*/
|
|
52
52
|
function makePropertiesChainable(item, config?: TConfig) {
|
|
53
|
+
const promiseCallableProps: any[] = ['then', 'catch', 'finally'];
|
|
53
54
|
const propsList = [];
|
|
55
|
+
|
|
54
56
|
if (isObject(config) && config.getEntityPropList) {
|
|
55
57
|
if (!isObject(config.getEntityPropList) && !isArray(config.getEntityPropList)) {
|
|
56
58
|
throw new TypeError('config "getEntityPropList" should be an array or an object');
|
|
@@ -103,8 +105,7 @@ function makePropertiesChainable(item, config?: TConfig) {
|
|
|
103
105
|
}
|
|
104
106
|
|
|
105
107
|
if (
|
|
106
|
-
p
|
|
107
|
-
p !== 'catch' &&
|
|
108
|
+
!promiseCallableProps.includes(p) &&
|
|
108
109
|
isUndefined(Reflect.get(item, p, r)) &&
|
|
109
110
|
isObject(config) &&
|
|
110
111
|
isFunction(config.extendProxed)
|
|
@@ -126,18 +127,36 @@ function makePropertiesChainable(item, config?: TConfig) {
|
|
|
126
127
|
const isCallable = isFunction(Reflect.get(item, p, r)) || isAsyncFunction(Reflect.get(item, p, r));
|
|
127
128
|
|
|
128
129
|
if (!isCallable && !isPromise(proxifiedResult) && item[p] && !proxifiedResult[p]) {
|
|
129
|
-
logger.
|
|
130
|
+
logger.chainer(`[CHAIN_SIMPLE]: ${String(p)} is not a callable.`);
|
|
131
|
+
|
|
130
132
|
return item[p];
|
|
131
133
|
} else if (isCallable) {
|
|
134
|
+
logger.chainer(`[CHAIN_SIMPLE]: ${String(p)} is a callable.`);
|
|
135
|
+
|
|
132
136
|
return function (...arguments_) {
|
|
133
|
-
|
|
134
|
-
|
|
137
|
+
logger.chainer(`[CHAIN_SIMPLE]: ${String(p)} is called with args: `, ...arguments);
|
|
138
|
+
|
|
139
|
+
if (isPromise(proxifiedResult)) {
|
|
140
|
+
logger.chainer(`[CHAIN_SIMPLE]: previous call result is a promise`);
|
|
141
|
+
proxifiedResult = proxifiedResult
|
|
142
|
+
.then(function (r) {
|
|
143
|
+
logger.chainer(`[CHAIN_SIMPLE]: previous call result is: `, r);
|
|
144
|
+
|
|
135
145
|
return item[p].call(item, ...arguments_);
|
|
136
146
|
})
|
|
137
|
-
|
|
147
|
+
.catch(e => console.log(e));
|
|
148
|
+
} else {
|
|
149
|
+
logger.chainer(`[CHAIN_SIMPLE]: previous call result is not a promise`);
|
|
150
|
+
logger.chainer(`[CHAIN_SIMPLE]: previous call result is: `, proxifiedResult);
|
|
151
|
+
|
|
152
|
+
proxifiedResult = item[p].call(item, ...arguments_);
|
|
153
|
+
}
|
|
154
|
+
|
|
138
155
|
return proxed;
|
|
139
156
|
};
|
|
140
|
-
} else if ((p
|
|
157
|
+
} else if (promiseCallableProps.includes(p) && isPromise(proxifiedResult)) {
|
|
158
|
+
logger.chainer(`[CHAIN_SIMPLE]: previous call result is a promise and next call is a promise method call`);
|
|
159
|
+
|
|
141
160
|
if (!isPromise(proxifiedResult)) {
|
|
142
161
|
return proxifiedResult;
|
|
143
162
|
}
|
package/lib/logger.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "chain-simple",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.2",
|
|
4
4
|
"description": "Main purpose of this package is - provide simple way to build chain between any item methods",
|
|
5
5
|
"main": "built/index.js",
|
|
6
6
|
"directories": {
|
|
@@ -55,6 +55,6 @@
|
|
|
55
55
|
"node": ">=12.18.3"
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"sat-utils": "1.
|
|
58
|
+
"sat-utils": "1.9.0"
|
|
59
59
|
}
|
|
60
60
|
}
|