chain-simple 2.0.0 → 2.2.0

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/.oxlintrc.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "$schema": "./node_modules/oxlint/configuration_schema.json",
3
+ "plugins": ["unicorn", "typescript", "promise", "jest"],
4
+ "env": {
5
+ "browser": true
6
+ },
7
+ "globals": {
8
+ "browser": "readonly"
9
+ },
10
+ "categories": {
11
+ "correctness": "error"
12
+ },
13
+ "ignorePatterns": ["built", "node_modules"],
14
+ "rules": {
15
+ "no-console": "error",
16
+ "no-unused-vars": "off",
17
+ "no-unassigned-vars": "off",
18
+ "jest/no-focused-tests": "error",
19
+ "jest/expect-expect": "off",
20
+ "jest/no-disabled-tests": "off",
21
+ "jest/valid-title": "off",
22
+ "jest/no-identical-title": "off",
23
+ "jest/no-conditional-expect": "off",
24
+ "unicorn/no-null": "off",
25
+ "unicorn/explicit-length-check": "off",
26
+ "unicorn/prevent-abbreviations": "off",
27
+ "unicorn/prefer-node-protocol": "off",
28
+ "unicorn/import-style": "off",
29
+ "unicorn/prefer-module": "off",
30
+ "unicorn/prefer-spread": "off",
31
+ "unicorn/consistent-destructuring": "off",
32
+ "unicorn/no-this-assignment": "off",
33
+ "unicorn/no-array-for-each": "off",
34
+ "unicorn/no-array-reduce": "off",
35
+ "unicorn/filename-case": "off",
36
+ "unicorn/no-abusive-eslint-disable": "off"
37
+ },
38
+ "overrides": [
39
+ {
40
+ "files": ["*.spec.ts", "*.test.ts"],
41
+ "rules": {
42
+ "no-console": "off",
43
+ "no-unused-expressions": "off"
44
+ }
45
+ }
46
+ ]
47
+ }
@@ -1,18 +1,14 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.chainProps = chainProps;
4
- exports.makeConstructorInstancePropertiesChainable = makeConstructorInstancePropertiesChainable;
5
- const sat_utils_1 = require("sat-utils");
6
- const logger_1 = require("./logger");
7
- logger_1.logger.setLogLevel(process.env.CHAIN_SIMPLE_LOG_LEVEL);
1
+ import { isArray, isObject, isPromise, isFunction, isAsyncFunction, canBeProxed, isUndefined } from 'sat-utils';
2
+ import { logger } from './logger';
3
+ logger.setLogLevel(process.env.CHAIN_SIMPLE_LOG_LEVEL);
8
4
  function extendProxed(target, propName, receiver, config) {
9
- if ((0, sat_utils_1.isObject)(config) && (0, sat_utils_1.isFunction)(config.extendProxed) && (0, sat_utils_1.isUndefined)(Reflect.get(target, propName, receiver))) {
5
+ if (isObject(config) && isFunction(config.extendProxed) && isUndefined(Reflect.get(target, propName, receiver))) {
10
6
  try {
11
7
  const extension = config.extendProxed(propName);
12
- if ((0, sat_utils_1.isObject)(extension)) {
8
+ if (isObject(extension)) {
13
9
  Object.assign(target, extension);
14
10
  }
15
- else if ((0, sat_utils_1.isFunction)(extension)) {
11
+ else if (isFunction(extension)) {
16
12
  const result = extension(target);
17
13
  Object.assign(target, result);
18
14
  }
@@ -57,18 +53,18 @@ function extendProxed(target, propName, receiver, config) {
57
53
  function chainProps(item, config) {
58
54
  const promiseCallableProps = ['then', 'catch', 'finally'];
59
55
  const propsList = [];
60
- if ((0, sat_utils_1.isObject)(config) && config.getEntityPropList) {
61
- if (!(0, sat_utils_1.isObject)(config.getEntityPropList) && !(0, sat_utils_1.isArray)(config.getEntityPropList)) {
56
+ if (isObject(config) && config.getEntityPropList) {
57
+ if (!isObject(config.getEntityPropList) && !isArray(config.getEntityPropList)) {
62
58
  throw new TypeError('config "getEntityPropList" should be an array or an object');
63
59
  }
64
- propsList.push(...((0, sat_utils_1.isObject)(config.getEntityPropList)
60
+ propsList.push(...(isObject(config.getEntityPropList)
65
61
  ? Object.keys(config.getEntityPropList)
66
62
  : config.getEntityPropList));
67
63
  }
68
- if (!(0, sat_utils_1.canBeProxed)(item)) {
64
+ if (!canBeProxed(item)) {
69
65
  throw new TypeError('chainProps(): first argument should be an entity that can be proxed');
70
66
  }
71
- if (!(0, sat_utils_1.isUndefined)(config) && !(0, sat_utils_1.isObject)(config)) {
67
+ if (!isUndefined(config) && !isObject(config)) {
72
68
  throw new TypeError('chainProps(): second argument should be an object');
73
69
  }
74
70
  const _config = { ...config };
@@ -77,7 +73,7 @@ function chainProps(item, config) {
77
73
  get(_t, p, r) {
78
74
  if (propsList.length && propsList.includes(p)) {
79
75
  const propValue = Reflect.getOwnPropertyDescriptor(item, p)?.value;
80
- if ((0, sat_utils_1.isFunction)(propValue) || (0, sat_utils_1.isAsyncFunction)(propValue)) {
76
+ if (isFunction(propValue) || isAsyncFunction(propValue)) {
81
77
  return item[p].bind(item);
82
78
  }
83
79
  return item[p];
@@ -105,33 +101,33 @@ function chainProps(item, config) {
105
101
  if (!promiseCallableProps.includes(p)) {
106
102
  extendProxed(item, p, r, config);
107
103
  }
108
- const isCallable = (0, sat_utils_1.isFunction)(Reflect.get(item, p, r)) || (0, sat_utils_1.isAsyncFunction)(Reflect.get(item, p, r));
109
- if (!isCallable && !(0, sat_utils_1.isPromise)(proxifiedResult) && item[p] && !proxifiedResult[p]) {
110
- logger_1.logger.chainer(`[CHAIN_SIMPLE]: ${String(p)} is not a callable.`);
104
+ const isCallable = isFunction(Reflect.get(item, p, r)) || isAsyncFunction(Reflect.get(item, p, r));
105
+ if (!isCallable && !isPromise(proxifiedResult) && item[p] && !proxifiedResult[p]) {
106
+ logger.chainer(`[CHAIN_SIMPLE]: ${String(p)} is not a callable.`);
111
107
  return item[p];
112
108
  }
113
109
  else if (isCallable) {
114
- logger_1.logger.chainer(`[CHAIN_SIMPLE]: ${String(p)} is a callable.`);
110
+ logger.chainer(`[CHAIN_SIMPLE]: ${String(p)} is a callable.`);
115
111
  return function (...arguments_) {
116
- logger_1.logger.chainer(`[CHAIN_SIMPLE]: ${String(p)} is called with args: `, ...arguments);
117
- if ((0, sat_utils_1.isPromise)(proxifiedResult)) {
118
- logger_1.logger.chainer(`[CHAIN_SIMPLE]: previous call result is a promise`);
112
+ logger.chainer(`[CHAIN_SIMPLE]: ${String(p)} is called with args: `, ...arguments);
113
+ if (isPromise(proxifiedResult)) {
114
+ logger.chainer(`[CHAIN_SIMPLE]: previous call result is a promise`);
119
115
  proxifiedResult = proxifiedResult.then(function (r) {
120
- logger_1.logger.chainer(`[CHAIN_SIMPLE]: previous call result is: `, r);
116
+ logger.chainer(`[CHAIN_SIMPLE]: previous call result is: `, r);
121
117
  return item[p].call(item, ...arguments_);
122
118
  });
123
119
  }
124
120
  else {
125
- logger_1.logger.chainer(`[CHAIN_SIMPLE]: previous call result is not a promise`);
126
- logger_1.logger.chainer(`[CHAIN_SIMPLE]: previous call result is: `, proxifiedResult);
121
+ logger.chainer(`[CHAIN_SIMPLE]: previous call result is not a promise`);
122
+ logger.chainer(`[CHAIN_SIMPLE]: previous call result is: `, proxifiedResult);
127
123
  proxifiedResult = item[p].call(item, ...arguments_);
128
124
  }
129
125
  return proxed;
130
126
  };
131
127
  }
132
- else if (promiseCallableProps.includes(p) && (0, sat_utils_1.isPromise)(proxifiedResult)) {
133
- logger_1.logger.chainer(`[CHAIN_SIMPLE]: previous call result is a promise and next call is a promise method call`);
134
- if (!(0, sat_utils_1.isPromise)(proxifiedResult)) {
128
+ else if (promiseCallableProps.includes(p) && isPromise(proxifiedResult)) {
129
+ logger.chainer(`[CHAIN_SIMPLE]: previous call result is a promise and next call is a promise method call`);
130
+ if (!isPromise(proxifiedResult)) {
135
131
  return proxifiedResult;
136
132
  }
137
133
  return function (onRes, onRej) {
@@ -171,4 +167,5 @@ function handlerConstructor(config) {
171
167
  function makeConstructorInstancePropertiesChainable(constructorFunction, config) {
172
168
  return new Proxy(constructorFunction, handlerConstructor(config));
173
169
  }
170
+ export { chainProps, makeConstructorInstancePropertiesChainable };
174
171
  //# sourceMappingURL=index.js.map
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.logger = void 0;
4
- const sat_utils_1 = require("sat-utils");
5
- const logger = (0, sat_utils_1.createLogger)().addCustomLevel('chainer', 'CHAIN_LOG', 'CHAIN_LOG', 'info', 'BgBlue', 'BgWhite');
6
- exports.logger = logger;
1
+ import { createLogger } from 'sat-utils';
2
+ const logger = createLogger().addCustomLevel('chainer', 'CHAIN_LOG', 'CHAIN_LOG', 'info', 'BgBlue', 'BgWhite');
3
+ export { logger };
7
4
  //# sourceMappingURL=logger.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chain-simple",
3
- "version": "2.0.0",
3
+ "version": "2.2.0",
4
4
  "description": "Main purpose of this package is - provide simple way to build chain between any item methods",
5
5
  "main": "./built/cjs/index.js",
6
6
  "exports": {
@@ -17,7 +17,7 @@
17
17
  "test": "LOG_LEVEL=VERBOSE mocha ./specs/**/*.spec.ts --require ts-node/register --timeout 30000",
18
18
  "test:verbose": "LOG_LEVEL=VERBOSE mocha ./specs/**/*.spec.ts --require ts-node/register --timeout 30000",
19
19
  "test:watch": "mocha ./specs/**/*.spec.ts --require ts-node/register --timeout 30000 --watch",
20
- "lint": "eslint --ext .ts ./",
20
+ "lint": "oxlint --fix",
21
21
  "tsc:cjs": "tsc -p tsconfig.json",
22
22
  "tsc:esm": "tsc -p tsconfig.esm.json",
23
23
  "tsc": "rm -rf ./built && npm run tsc:cjs && npm run tsc:esm",
@@ -45,24 +45,19 @@
45
45
  },
46
46
  "homepage": "https://github.com/Simple-Automation-Testing/chain-simple#readme",
47
47
  "devDependencies": {
48
- "@types/mocha": "^8.2.0",
49
- "@typescript-eslint/eslint-plugin": "^4.11.1",
50
- "@typescript-eslint/parser": "^4.11.1",
51
- "assertior": "0.0.23",
52
- "eslint": "^7.16.0",
53
- "eslint-plugin-chai-expect": "^2.2.0",
54
- "eslint-plugin-chai-friendly": "^0.6.0",
55
- "eslint-plugin-mocha": "^8.0.0",
56
- "mocha": "^8.2.1",
57
- "prettier": "^2.6.2",
48
+ "@types/mocha": "^10.0.10",
49
+ "assertior": "^0.0.28",
50
+ "mocha": "^11.7.5",
51
+ "oxlint": "^1.43.0",
52
+ "prettier": "^3.8.1",
58
53
  "ts-node": "^10.9.2",
59
- "typescript": "^5.8.3"
54
+ "typescript": "^5.9.3"
60
55
  },
61
56
  "engines": {
62
57
  "node": ">=20.9.0"
63
58
  },
64
59
  "dependencies": {
65
- "sat-utils": "1.9.0"
60
+ "sat-utils": "3.2.0"
66
61
  }
67
62
  }
68
63
 
package/tsconfig.esm.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "module": "NodeNext",
3
+ "module": "ESNext",
4
+ "moduleResolution": "bundler",
4
5
  "target": "ESNext",
5
6
  "sourceMap": true,
6
7
  "outDir": "built/esm",
package/.eslintignore DELETED
@@ -1 +0,0 @@
1
- built
package/.eslintrc.js DELETED
@@ -1,38 +0,0 @@
1
- module.exports = {
2
- plugins: ['sonarjs', 'promise', 'unicorn', 'prettier', 'no-only-tests'],
3
- parser: '@typescript-eslint/parser',
4
- rules: {
5
- 'jsdoc/valid-types': 'off',
6
- 'jsdoc/check-property-names': 'off',
7
- 'no-await-in-loop': 'off',
8
- 'unicorn/no-null': 'off',
9
- 'jsdoc/no-undefined-types': 'off',
10
- 'unicorn/explicit-length-check': 'off',
11
- 'no-restricted-syntax': 'off',
12
- 'func-names': 'off',
13
- 'no-plusplus': 'off',
14
- 'unicorn/prevent-abbreviations': 'off',
15
- 'unicorn/no-reduce': 'off',
16
- 'no-unused-expressions': 'off',
17
- 'unicorn/prefer-node-protocol': 'off',
18
- 'unicorn/import-style': 'off',
19
- 'no-useless-constructor': 'off',
20
- 'unicorn/prefer-module': 'off',
21
- 'unicorn/prefer-spread': 'off',
22
- 'unicorn/consistent-destructuring': 'off',
23
- 'import/no-unresolved': 'off',
24
- 'unicorn/no-this-assignment': 'off',
25
- 'unicorn/no-array-for-each': 'off',
26
- 'default-case': 'off',
27
- 'sonarjs/no-duplicate-string': 'off',
28
- 'unicorn/no-array-reduce': 'off',
29
- 'unicorn/filename-case': 'off',
30
- 'unicorn/no-abusive-eslint-disable': 'off',
31
- 'no-only-tests/no-only-tests': 'error',
32
- 'no-console': 'error',
33
- },
34
- extends: ['plugin:sonarjs/recommended', 'plugin:unicorn/recommended', 'prettier', 'plugin:prettier/recommended'],
35
- globals: {
36
- browser: 'readonly',
37
- },
38
- };