chain-simple 0.0.1 → 0.0.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/.eslintrc.js CHANGED
@@ -1,75 +1,38 @@
1
1
  module.exports = {
2
- 'env': {
3
- 'browser': true,
4
- 'commonjs': true,
5
- 'es6': true,
6
- 'node': true,
7
- 'mocha': true
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',
8
33
  },
9
- 'globals': {
10
- 'describe:': 'readonly'
34
+ extends: ['plugin:sonarjs/recommended', 'plugin:unicorn/recommended', 'prettier', 'plugin:prettier/recommended'],
35
+ globals: {
36
+ browser: 'readonly',
11
37
  },
12
- 'parser': '@typescript-eslint/parser',
13
- 'plugins': [
14
- '@typescript-eslint',
15
- 'mocha',
16
- 'chai-expect',
17
- 'chai-friendly'
18
- ],
19
- 'parserOptions': {
20
- 'ecmaVersion': 2018
21
- },
22
- 'rules': {
23
- '@typescript-eslint/naming-convention': [
24
- 'error',
25
- {
26
- 'selector': 'typeParameter',
27
- 'format': ['PascalCase'],
28
- 'prefix': ['T']
29
- }
30
- ],
31
- 'no-undefined': 'off',
32
- '@typescript-eslint/ban-ts-comment': 'off',
33
- '@typescript-eslint/no-use-before-define': 'off',
34
- '@typescript-eslint/explicit-module-boundary-types': 'off',
35
- '@typescript-eslint/camelcase': 'off',
36
- '@typescript-eslint/ban-ts-ignore': 'off',
37
- '@typescript-eslint/no-explicit-any': 'off',
38
- '@typescript-eslint/interface-name-prefix': 'off',
39
- '@typescript-eslint/explicit-function-return-type': 'off',
40
- '@typescript-eslint/no-var-requires': 'off',
41
- 'no-console': 2,
42
- 'arrow-parens': 2,
43
- 'require-atomic-updates': 'off',
44
- 'eol-last': ['error', 'always'],
45
- 'max-len': ['error', {'code': 140, 'tabWidth': 2}],
46
- 'prefer-const': ['error', {'destructuring': 'any', 'ignoreReadBeforeAssign': false}],
47
- 'space-in-parens': [2, 'never'],
48
- 'no-trailing-spaces': ['error'],
49
- 'semi': [2, 'always'],
50
- 'no-multiple-empty-lines': [2, {'max': 2}],
51
- 'quotes': ['error', 'single', {'allowTemplateLiterals': true}],
52
- 'valid-jsdoc': ['error', {'requireParamDescription': false, 'requireReturnDescription': false}],
53
- 'no-shadow': 'off',
54
- 'space-before-function-paren': ['error', {'anonymous': 'never', 'named': 'never', 'asyncArrow': 'always'}],
55
- 'require-jsdoc': 'off', //['error', {'require': {'FunctionDeclaration': true, 'MethodDefinition': true}}],
56
- 'keyword-spacing': ['error'],
57
- 'chai-friendly/no-unused-expressions': 'off',
58
- 'no-undef-init': ['error'],
59
- 'comma-spacing': ['error'],
60
- 'brace-style': ['error'],
61
- '@typescript-eslint/no-unused-vars': 'off',
62
- 'no-irregular-whitespace': 'off',
63
- 'mocha/no-mocha-arrows': 'off',
64
- 'chai-expect/no-inner-compare': 'off',
65
- '@typescript-eslint/no-this-alias': 'off'
66
- },
67
- 'extends': [
68
- 'eslint:recommended',
69
- 'plugin:mocha/recommended',
70
- 'plugin:chai-expect/recommended',
71
- 'plugin:chai-friendly/recommended',
72
- 'plugin:@typescript-eslint/recommended',
73
- 'plugin:@typescript-eslint/eslint-recommended'
74
- ]
75
38
  };
package/.prettierrc ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "singleQuote": true,
3
+ "trailingComma": "all",
4
+ "arrowParens": "avoid",
5
+ "printWidth": 120,
6
+ "tabWidth": 2,
7
+ "useTabs": false,
8
+ "semi": true,
9
+ "bracketSpacing": true,
10
+ "proseWrap": "never"
11
+ }
package/built/index.d.ts CHANGED
@@ -1 +1,5 @@
1
- export * from './proxy.helper';
1
+ declare function wrapObj(item: any, config?: {
2
+ getEntity: string;
3
+ }): any;
4
+ declare function wrapConstruct(constructorFunction: any): any;
5
+ export { wrapConstruct, wrapObj };
package/built/index.js CHANGED
@@ -1,14 +1,120 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
- };
12
2
  Object.defineProperty(exports, "__esModule", { value: true });
13
- __exportStar(require("./proxy.helper"), exports);
3
+ exports.wrapObj = exports.wrapConstruct = void 0;
4
+ const sat_utils_1 = require("sat-utils");
5
+ sat_utils_1.logger.setLogLevel(process.env.LOG_LEVEL);
6
+ function wrapObj(item, config) {
7
+ if (!sat_utils_1.canBeProxed(item)) {
8
+ throw new TypeError('first argument should be an entity that can be proxed');
9
+ }
10
+ if (!sat_utils_1.isUndefined(config) && !sat_utils_1.isObject(config)) {
11
+ throw new TypeError('second argument should be an object');
12
+ }
13
+ let proxifiedResult = item;
14
+ const proxed = new Proxy(item, {
15
+ get(_t, p) {
16
+ if (config && config.getEntity === p) {
17
+ return item;
18
+ }
19
+ sat_utils_1.logger.info(p);
20
+ if (p === Symbol.toStringTag) {
21
+ return proxifiedResult[Symbol.toStringTag];
22
+ }
23
+ if (p === 'toString') {
24
+ return function (...args) {
25
+ return proxifiedResult.toString(...args);
26
+ };
27
+ }
28
+ if (p === 'toJSON') {
29
+ sat_utils_1.logger.info('In to JSON');
30
+ return function () {
31
+ return proxifiedResult;
32
+ };
33
+ }
34
+ if (!sat_utils_1.isFunction(item[p]) &&
35
+ !sat_utils_1.isAsyncFunction(item[p]) &&
36
+ !sat_utils_1.isPromise(proxifiedResult) &&
37
+ item[p] &&
38
+ !proxifiedResult[p]) {
39
+ sat_utils_1.logger.info('In to not function, not async function, resulter is not a promise and target has prop');
40
+ return item[p];
41
+ }
42
+ else if ((sat_utils_1.isFunction(item[p]) || sat_utils_1.isAsyncFunction(item[p])) && sat_utils_1.isPromise(proxifiedResult)) {
43
+ sat_utils_1.logger.info('In to function or async function and resulter is a promise');
44
+ return function (...arguments_) {
45
+ async function handler() {
46
+ await proxifiedResult;
47
+ return item[p](...arguments_);
48
+ }
49
+ proxifiedResult = handler();
50
+ return proxed;
51
+ };
52
+ }
53
+ else if (sat_utils_1.isAsyncFunction(item[p]) && !sat_utils_1.isPromise(proxifiedResult)) {
54
+ sat_utils_1.logger.info('In to async function and resulter is a promise');
55
+ return function (...arguments_) {
56
+ async function handler() {
57
+ return item[p](...arguments_);
58
+ }
59
+ proxifiedResult = handler();
60
+ return proxed;
61
+ };
62
+ }
63
+ else if (sat_utils_1.isFunction(item[p]) && !sat_utils_1.isPromise(proxifiedResult)) {
64
+ sat_utils_1.logger.info('In to function and resulter is not a promise');
65
+ return function (...arguments_) {
66
+ proxifiedResult = item[p](...arguments_);
67
+ return proxed;
68
+ };
69
+ }
70
+ else if ((p === 'then' || p === 'catch') && sat_utils_1.isPromise(proxifiedResult)) {
71
+ sat_utils_1.logger.info('In then catch');
72
+ /** @info logging */
73
+ sat_utils_1.logger.info('start call promise: ', p);
74
+ if (!sat_utils_1.isPromise(proxifiedResult)) {
75
+ return proxifiedResult;
76
+ }
77
+ return async function (onRes, onRej) {
78
+ const catcher = p === 'catch' ? onRes : onRej;
79
+ proxifiedResult = await proxifiedResult.catch(error => ({ error, ____proxed____error: true }));
80
+ if (proxifiedResult && proxifiedResult.____proxed____error) {
81
+ return catcher(proxifiedResult.error);
82
+ }
83
+ const promised = Promise.resolve(proxifiedResult);
84
+ return promised[p].call(promised, onRes, onRej);
85
+ };
86
+ }
87
+ else if (proxifiedResult[p]) {
88
+ sat_utils_1.logger.info('In resulter has prop');
89
+ return proxifiedResult[p];
90
+ }
91
+ if (!(p in item) && p in proxifiedResult) {
92
+ sat_utils_1.logger.info('In target does not have prop but resulter has prop');
93
+ return proxifiedResult[p];
94
+ }
95
+ },
96
+ /** @info basics */
97
+ getPrototypeOf(_t) {
98
+ return Object.getPrototypeOf(proxifiedResult);
99
+ },
100
+ ownKeys(_t) {
101
+ return Object.getOwnPropertyNames(proxifiedResult);
102
+ },
103
+ getOwnPropertyDescriptor(_t, p) {
104
+ return Object.getOwnPropertyDescriptor(proxifiedResult, p);
105
+ },
106
+ });
107
+ return proxed;
108
+ }
109
+ exports.wrapObj = wrapObj;
110
+ const handlerConstructor = {
111
+ construct(target, args) {
112
+ const item = new target(...args);
113
+ return wrapObj(item);
114
+ },
115
+ };
116
+ function wrapConstruct(constructorFunction) {
117
+ return new Proxy(constructorFunction, handlerConstructor);
118
+ }
119
+ exports.wrapConstruct = wrapConstruct;
14
120
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,18 +1,19 @@
1
1
  {
2
2
  "name": "chain-simple",
3
- "version": "0.0.1",
4
- "description": "## Main purpose of this package is to provide integration of the common assertions into class methods without refactoring and updates of the class methods and provide chain between class methods, this package does not affect constructor, getters/setters and does not affect internal logic of the class methods. Package works with async function/Promises, and also with sync common code",
3
+ "version": "0.0.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": {
7
7
  "example": "examples",
8
8
  "lib": "lib"
9
9
  },
10
10
  "scripts": {
11
- "test": "LOG_LEVEL=ERROR mocha ./specs/**/*.spec.ts --require ts-node/register --timeout 30000",
11
+ "test": "LOG_LEVEL=VERBOSE mocha ./specs/**/*.spec.ts --require ts-node/register --timeout 30000",
12
12
  "test:verbose": "LOG_LEVEL=VERBOSE mocha ./specs/**/*.spec.ts --require ts-node/register --timeout 30000",
13
13
  "test:watch": "mocha ./specs/**/*.spec.ts --require ts-node/register --timeout 30000 --watch",
14
14
  "lint": "eslint --ext .ts ./",
15
- "build": "rm -rf ./built && tsc"
15
+ "build": "rm -rf ./built && tsc",
16
+ "build:prepublish": "rm -rf ./built && tsc --sourceMap false"
16
17
  },
17
18
  "keywords": [
18
19
  "proxy object",
@@ -22,36 +23,38 @@
22
23
  "proxy method",
23
24
  "chaining",
24
25
  "chain",
25
- "chain methods"
26
+ "chain methods",
27
+ "wrap in chain"
26
28
  ],
27
29
  "repository": {
28
30
  "type": "git",
29
- "url": "git+https://github.com/Simple-Automation-Testing/simple-chain.git"
31
+ "url": "git+https://github.com/Simple-Automation-Testing/chain-simple.git"
30
32
  },
31
33
  "author": "",
32
34
  "license": "ISC",
33
35
  "bugs": {
34
- "url": "https://github.com/Simple-Automation-Testing/simple-chain/issues"
36
+ "url": "https://github.com/Simple-Automation-Testing/chain-simple/issues"
35
37
  },
36
- "homepage": "https://github.com/Simple-Automation-Testing/simple-chain#readme",
38
+ "homepage": "https://github.com/Simple-Automation-Testing/chain-simple#readme",
37
39
  "devDependencies": {
38
- "@types/mocha": "^8.0.1",
39
- "@types/node": "^14.0.27",
40
- "@typescript-eslint/eslint-plugin": "^3.8.0",
41
- "@typescript-eslint/parser": "^3.8.0",
42
- "assertior": "^0.0.22",
43
- "eslint": "^7.6.0",
40
+ "@types/mocha": "^8.2.0",
41
+ "@types/node": "^14.14.17",
42
+ "@typescript-eslint/eslint-plugin": "^4.11.1",
43
+ "@typescript-eslint/parser": "^4.11.1",
44
+ "assertior": "0.0.23",
45
+ "eslint": "^7.16.0",
44
46
  "eslint-plugin-chai-expect": "^2.2.0",
45
47
  "eslint-plugin-chai-friendly": "^0.6.0",
46
48
  "eslint-plugin-mocha": "^8.0.0",
47
- "mocha": "^8.1.1",
48
- "ts-node": "^9.0.0",
49
- "typescript": "^4.0.3"
49
+ "mocha": "^8.2.1",
50
+ "prettier": "^2.6.2",
51
+ "ts-node": "^9.1.1",
52
+ "typescript": "^4.1.3"
50
53
  },
51
54
  "engines": {
52
55
  "node": ">=12.18.3"
53
56
  },
54
57
  "dependencies": {
55
- "sat-utils": "^0.0.3"
58
+ "sat-utils": "^0.0.42"
56
59
  }
57
- }
60
+ }
package/readme.md CHANGED
@@ -1,6 +1,40 @@
1
+ # chain-simple
1
2
 
2
- # simple-chain
3
3
 
4
- ## Main purpose of this package is to provide integration of the common assertions into class methods without refactoring and updates of the class methods and provide chain between class methods, this package does not affect constructor, getters/setters and does not affect internal logic of the class methods. Package works with async function/Promises, and also with sync common code
4
+ ![npm downloads](https://img.shields.io/npm/dm/chain-simple.svg?style=flat-square)
5
5
 
6
- ![npm downloads](https://img.shields.io/npm/dm/proxify-method.svg?style=flat-square)
6
+ The purpose of this library is - build simple and flexible chainable call of the object` methods
7
+
8
+ ```js
9
+ const {wrapObj} = require('chain-simple');
10
+
11
+ const yourObjectWithMethods = {
12
+ async method1() {
13
+ return Promise.resolve(1).then(value => {
14
+ console.log('method1', value);
15
+ return value;
16
+ });
17
+ },
18
+ async method2() {
19
+ return Promise.resolve(2).then(value => {
20
+ console.log('method2', value);
21
+ return value;
22
+ });
23
+ },
24
+ async method3() {
25
+ return Promise.resolve(3).then(value => {
26
+ console.log('method3', value);
27
+ return value;
28
+ });
29
+ },
30
+ };
31
+
32
+ const wrappedObj = wrapObj(yourObjectWithMethods);
33
+
34
+ testExample();
35
+ async function testExample() {
36
+ const result = await wrappedObj.method1().method2().method3().method1();
37
+
38
+ console.log(result);
39
+ }
40
+ ```
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iDAA+B"}
@@ -1,8 +0,0 @@
1
- /**
2
- * @info
3
- * @resulter can be a promise or any data
4
- */
5
- declare function proxifyHadler(originalCaller: any, context: any, chainers: {
6
- [k: string]: (...args: any[]) => any;
7
- }, config?: any): any;
8
- export { proxifyHadler };
@@ -1,95 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.proxifyHadler = void 0;
4
- const sat_utils_1 = require("sat-utils");
5
- const { LOG_LEVEL = 'VERBOSE' } = process.env;
6
- sat_utils_1.logger.setLogLevel(LOG_LEVEL);
7
- /**
8
- * @info
9
- * @resulter can be a promise or any data
10
- */
11
- function proxifyHadler(originalCaller, context, chainers, config = {}) {
12
- const { fromResult = false } = config;
13
- /**
14
- * @info
15
- * this is required for sync call execution
16
- */
17
- let proxifiedResult = originalCaller();
18
- let proxed = new Proxy(proxifiedResult, {
19
- get(_t, p) {
20
- if (p === 'toJSON') {
21
- return function () {
22
- return proxifiedResult;
23
- };
24
- }
25
- if (chainers[p] && sat_utils_1.isPromise(proxifiedResult)) {
26
- /** @info logging */
27
- sat_utils_1.logger.info('add to chain chainers function: ', p);
28
- return function (...expectation) {
29
- async function handler() {
30
- const resolved = await proxifiedResult;
31
- return chainers[p](...expectation, resolved);
32
- }
33
- proxifiedResult = handler();
34
- return proxed;
35
- };
36
- }
37
- else if (chainers[p] && !sat_utils_1.isPromise(proxifiedResult)) {
38
- /** @info logging */
39
- sat_utils_1.logger.info('add sync call to chain chainers function: ', p);
40
- return function (...expectation) {
41
- const result = chainers[p](...expectation, proxifiedResult);
42
- /** @info for sync proxing approach */
43
- if (fromResult) {
44
- proxifiedResult = result;
45
- }
46
- return proxed;
47
- };
48
- }
49
- else if (sat_utils_1.isFunction(context[p])) {
50
- /** @info logging */
51
- const handler = this;
52
- sat_utils_1.logger.info('add to chain context function: ', p);
53
- return function (...args) {
54
- proxifiedResult = context[p].call(context, ...args);
55
- /** @info this is required for sync execution and context */
56
- proxed = new Proxy(proxifiedResult, handler);
57
- return proxed;
58
- };
59
- }
60
- else if (p === 'then' || p === 'catch') {
61
- /** @info logging */
62
- sat_utils_1.logger.info('start call promise: ', p);
63
- if (!sat_utils_1.isPromise(proxifiedResult)) {
64
- return proxifiedResult;
65
- }
66
- return async function (onRes, onRej) {
67
- const catcher = p === 'catch' ? onRes : onRej;
68
- proxifiedResult = await proxifiedResult
69
- .catch((error) => ({ error, ____proxed____error: true }));
70
- if (proxifiedResult && proxifiedResult.____proxed____error) {
71
- return catcher(proxifiedResult.error);
72
- }
73
- const promised = Promise.resolve(proxifiedResult);
74
- return promised[p].call(promised, onRes, onRej);
75
- };
76
- }
77
- else if (proxifiedResult[p]) {
78
- return proxifiedResult[p];
79
- }
80
- },
81
- /** @info basics */
82
- getPrototypeOf(_t) {
83
- return Object.getPrototypeOf(proxifiedResult);
84
- },
85
- ownKeys(_t) {
86
- return Object.getOwnPropertyNames(proxifiedResult);
87
- },
88
- getOwnPropertyDescriptor(_t, p) {
89
- return Object.getOwnPropertyDescriptor(proxifiedResult, p);
90
- }
91
- });
92
- return proxed;
93
- }
94
- exports.proxifyHadler = proxifyHadler;
95
- //# sourceMappingURL=proxify.handler.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"proxify.handler.js","sourceRoot":"","sources":["../lib/proxify.handler.ts"],"names":[],"mappings":";;;AAAA,yCAAwD;AACxD,MAAM,EAAC,SAAS,GAAG,SAAS,EAAC,GAAG,OAAO,CA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oBAClD,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;gBAClD,CAAC,CAAC;aACH;iBAAM,IAAI,eAAe,CAAC,CAAC,CAAC,EAAE;gBAC7B,OAAO,eAAe,CAAC,CAAC,CAAC,CAAC;aAC3B;QACH,CAAC;QAED,mBAAmB;QAEnB,cAAc,CAAC,EAAE;YACf,OAAO,MAAM,CAAC,cAAc,CAAC,eAAe,CAAC,CAAC;QAChD,CAAC;QACD,OAAO,CAAC,EAAE;YACR,OAAO,MAAM,CAAC,mBAAmB,CAAC,eAAe,CAAC,CAAC;QACrD,CAAC;QACD,wBAAwB,CAAC,EAAE,EAAE,CAAC;YAC5B,OAAO,MAAM,CAAC,wBAAwB,CAAC,eAAe,EAAE,CAAC,CAAC,CAAC;QAC7D,CAAC;KACF,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC;AAGC,sCAAa"}
@@ -1,27 +0,0 @@
1
- declare type ChainerTypeFn = (...args: any[]) => any | void;
2
- declare type ChainerTypeChainerObj = {
3
- [k: string]: (...args: any[]) => any | void;
4
- };
5
- declare type ChainerTypeArrayFns = Array<(...args: any[]) => any | void>;
6
- declare type ChainerTypeArrayChainerObj = Array<{
7
- [k: string]: (...args: any[]) => any;
8
- }>;
9
- declare type ChainerTypeArrayWithBothTypes = Array<((...args: any[]) => any | void) | {
10
- [k: string]: (...args: any[]) => any;
11
- }>;
12
- /**
13
- * @example
14
- * const bothTypes: ChainerTypeArrayWithBothTypes = [function test() {}, {name: 'test', chain: function() {}}];
15
- * const fnType: ChainerTypeFn = function test () {};
16
- * const objType: ChainerTypeChainerObj = {name: 'test', chain: function() {}};
17
- * ...etc
18
- */
19
- declare type ChainerType = ChainerTypeFn | ChainerTypeChainerObj | ChainerTypeArrayFns | ChainerTypeArrayChainerObj | ChainerTypeArrayWithBothTypes;
20
- interface IProxifyItConfig {
21
- chainResult?: boolean;
22
- }
23
- declare function proxifyIt(config?: IProxifyItConfig): {
24
- addChain(chainer: ChainerType): any;
25
- baseOnPrototype(): (constructorFunction: any) => void;
26
- };
27
- export { proxifyIt };
@@ -1,108 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.proxifyIt = void 0;
4
- const proxify_handler_1 = require("./proxify.handler");
5
- const sat_utils_1 = require("sat-utils");
6
- function callable(originalMethodCaller, context, chainers, config) {
7
- return proxify_handler_1.proxifyHadler(originalMethodCaller, context, chainers, config);
8
- }
9
- function proxifyIt(config) {
10
- const shouldBeDecorated = [];
11
- const chainers = {};
12
- const proxifyItIterface = {
13
- addChain(chainer) {
14
- /**
15
- * @info in case if some unexpeted argument - Error
16
- */
17
- if (!chainer) {
18
- throw new Error(`
19
- addChain argument shoulb be
20
- () => any | {name: string, chai: () => any} | Array<() => any> | Array<{name: string, chai: () => any}>
21
- `);
22
- }
23
- if (sat_utils_1.isArray(chainer)) {
24
- chainer.forEach((_chainer) => {
25
- /**
26
- * @info in case if some unexpeted argument - Error
27
- */
28
- if (!_chainer || (sat_utils_1.isObject(_chainer) && (!_chainer.name || !_chainer.chain))) {
29
- throw new Error(`
30
- chainer in array should be
31
- (() => any|void) | {name: string, chai: () => any}
32
- `);
33
- }
34
- if (sat_utils_1.isFunction(_chainer) && _chainer.name) {
35
- return Object.assign(chainers, { [_chainer.name]: _chainer });
36
- }
37
- if (sat_utils_1.isObject(_chainer)) {
38
- return Object.assign(chainers, _chainer);
39
- }
40
- });
41
- return proxifyItIterface;
42
- }
43
- else if (sat_utils_1.isObject(chainer)) {
44
- const keys = Object.keys(chainer).forEach((chainerKey) => {
45
- if (!sat_utils_1.isFunction(chainer[chainerKey])) {
46
- throw new Error(`
47
- chainer obj should be
48
- {{[_chainer.name as string]: chai: () => any | void}
49
- `);
50
- }
51
- });
52
- Object.assign(chainers, chainer);
53
- return proxifyItIterface;
54
- }
55
- else if (sat_utils_1.isFunction(chainer)) {
56
- if (!chainer.name) {
57
- throw new Error(`chainer function should not be anonymous function`);
58
- }
59
- Object.assign(chainers, { [chainer.name]: chainer });
60
- return proxifyItIterface;
61
- }
62
- },
63
- baseOnPrototype() {
64
- return function (constructorFunction) {
65
- const prot = constructorFunction.prototype;
66
- const ownPropsList = Object.getOwnPropertyNames(prot);
67
- const protMethods = ownPropsList
68
- /**
69
- * @info ignore constructor function
70
- */
71
- .filter((fnName) => fnName !== 'constructor')
72
- .filter((fnName) => {
73
- const descriptor = Object.getOwnPropertyDescriptor(prot, fnName);
74
- /**
75
- * @info ignore getters and setters
76
- */
77
- if (descriptor.set || descriptor.get) {
78
- return false;
79
- }
80
- /**
81
- * @info only configurable methods can be proxified
82
- */
83
- if (descriptor.configurable && (typeof descriptor.value).includes('function')) {
84
- return true;
85
- }
86
- });
87
- protMethods.forEach((fnName) => {
88
- const descriptor = Object.getOwnPropertyDescriptor(prot, fnName);
89
- /**
90
- * @info original method
91
- */
92
- const originalMethod = descriptor.value;
93
- descriptor.value = function (...args) {
94
- /**
95
- * @info TBD
96
- */
97
- const executableMethod = originalMethod.bind(this, ...args);
98
- return callable(executableMethod, this, chainers, config);
99
- };
100
- Object.defineProperty(prot, fnName, descriptor);
101
- });
102
- };
103
- }
104
- };
105
- return proxifyItIterface;
106
- }
107
- exports.proxifyIt = proxifyIt;
108
- //# sourceMappingURL=proxy.helper.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"proxy.helper.js","sourceRoot":"","sources":["../lib/proxy.helper.ts"],"names":[],"mappings":";;;AAAA,uDAAgD;AAChD,yCAAwD;AAExD,SAAS,QAAQ,CAAC,oBAAsC,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM;IACjF,OAAO,+BAAa,CAAC,oBAAoB,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;AACxE,CAAC;AAqBD,SAAS,SAAS,CAAC,MAAyB;IAC1C,MAAM,iBAAiB,GAAG,EAAE,CAAC;IAC7B,MAAM,QAAQ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AC,KAAK,CAAC;oBAExC,UAAU,CAAC,KAAK,GAAG,UAAS,GAAG,IAAI;wBACjC;;0BAEE;wBACF,MAAM,gBAAgB,GAAG,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC;wBAC5D,OAAO,QAAQ,CAAC,gBAAgB,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;oBAC5D,CAAC,CAAC;oBACF,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC;gBAClD,CAAC,CAAC,CAAC;YACL,CAAC,CAAC;QACJ,CAAC;KACF,CAAC;IACF,OAAO,iBAAiB,CAAC;AAC3B,CAAC;AAGC,8BAAS"}
package/built/utils.d.ts DELETED
@@ -1,2 +0,0 @@
1
- declare function sleep(millisecond?: number): Promise<void>;
2
- export { sleep };
package/built/utils.js DELETED
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sleep = void 0;
4
- async function sleep(millisecond = 5 * 1000) {
5
- return new Promise((res) => setTimeout(res, millisecond));
6
- }
7
- exports.sleep = sleep;
8
- //# sourceMappingURL=utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../lib/utils.ts"],"names":[],"mappings":";;;AAAA,KAAK,UAAU,KAAK,CAAC,cAAsB,CAAC,GAAG,IAAI;IACjD,OAAO,IAAI,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC;AAC5D,CAAC;AAGC,sBAAK"}