chain-simple 1.3.0 → 1.3.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/built/index.js +18 -8
- package/built/logger.d.ts +2 -8
- package/built/logger.js +1 -1
- package/lib/index.ts +26 -9
- 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,30 @@ 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.then(function (r) {
|
|
113
|
+
logger_1.logger.chainer(`[CHAIN_SIMPLE]: previous call result is: `, r);
|
|
110
114
|
return item[p].call(item, ...arguments_);
|
|
111
|
-
})
|
|
112
|
-
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
logger_1.logger.chainer(`[CHAIN_SIMPLE]: previous call result is not a promise`);
|
|
119
|
+
logger_1.logger.chainer(`[CHAIN_SIMPLE]: previous call result is: `, proxifiedResult);
|
|
120
|
+
proxifiedResult = item[p].call(item, ...arguments_);
|
|
121
|
+
}
|
|
113
122
|
return proxed;
|
|
114
123
|
};
|
|
115
124
|
}
|
|
116
|
-
else if ((p
|
|
125
|
+
else if (promiseCallableProps.includes(p) && (0, sat_utils_1.isPromise)(proxifiedResult)) {
|
|
126
|
+
logger_1.logger.chainer(`[CHAIN_SIMPLE]: previous call result is a promise and next call is a promise method call`);
|
|
117
127
|
if (!(0, sat_utils_1.isPromise)(proxifiedResult)) {
|
|
118
128
|
return proxifiedResult;
|
|
119
129
|
}
|
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,34 @@ 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
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
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.then(function (r) {
|
|
142
|
+
logger.chainer(`[CHAIN_SIMPLE]: previous call result is: `, r);
|
|
143
|
+
|
|
144
|
+
return item[p].call(item, ...arguments_);
|
|
145
|
+
});
|
|
146
|
+
} else {
|
|
147
|
+
logger.chainer(`[CHAIN_SIMPLE]: previous call result is not a promise`);
|
|
148
|
+
logger.chainer(`[CHAIN_SIMPLE]: previous call result is: `, proxifiedResult);
|
|
149
|
+
|
|
150
|
+
proxifiedResult = item[p].call(item, ...arguments_);
|
|
151
|
+
}
|
|
152
|
+
|
|
138
153
|
return proxed;
|
|
139
154
|
};
|
|
140
|
-
} else if ((p
|
|
155
|
+
} else if (promiseCallableProps.includes(p) && isPromise(proxifiedResult)) {
|
|
156
|
+
logger.chainer(`[CHAIN_SIMPLE]: previous call result is a promise and next call is a promise method call`);
|
|
157
|
+
|
|
141
158
|
if (!isPromise(proxifiedResult)) {
|
|
142
159
|
return proxifiedResult;
|
|
143
160
|
}
|
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.3",
|
|
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
|
}
|