chain-simple 1.2.1 → 1.2.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.d.ts CHANGED
@@ -7,7 +7,9 @@ type TConfig = {
7
7
  getEntity?: string;
8
8
  extendProxed?: (propName: any) => {
9
9
  [k: string]: any;
10
- };
10
+ } | ((item: any) => {
11
+ [k: string]: any;
12
+ });
11
13
  };
12
14
  /**
13
15
  * @example
package/built/index.js CHANGED
@@ -68,7 +68,14 @@ function makePropertiesChainable(item, config) {
68
68
  (0, sat_utils_1.isFunction)(config.extendProxed)) {
69
69
  try {
70
70
  const extension = config.extendProxed(p);
71
- Object.assign(item, extension);
71
+ if ((0, sat_utils_1.isObject)(extension)) {
72
+ Object.assign(item, extension);
73
+ }
74
+ else if ((0, sat_utils_1.isFunction)(extension)) {
75
+ // @ts-ignore
76
+ const result = extension(item);
77
+ Object.assign(item, result);
78
+ }
72
79
  }
73
80
  catch (error) {
74
81
  console.error(error);
package/lib/index.ts CHANGED
@@ -12,7 +12,10 @@ export type TChainable<T extends Record<string, TFn>> = {
12
12
  [K in keyof T]: TReplaceReturnType<T[K], ReturnType<T[K]> & TChainable<T>>;
13
13
  };
14
14
 
15
- type TConfig = { getEntity?: string; extendProxed?: (propName) => { [k: string]: any } };
15
+ type TConfig = {
16
+ getEntity?: string;
17
+ extendProxed?: (propName) => { [k: string]: any } | ((item: any) => { [k: string]: any });
18
+ };
16
19
 
17
20
  /**
18
21
  * @example
@@ -85,7 +88,13 @@ function makePropertiesChainable(item, config?: TConfig) {
85
88
  ) {
86
89
  try {
87
90
  const extension = config.extendProxed(p);
88
- Object.assign(item, extension);
91
+ if (isObject(extension)) {
92
+ Object.assign(item, extension);
93
+ } else if (isFunction(extension)) {
94
+ // @ts-ignore
95
+ const result = extension(item);
96
+ Object.assign(item, result);
97
+ }
89
98
  } catch (error) {
90
99
  console.error(error);
91
100
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chain-simple",
3
- "version": "1.2.1",
3
+ "version": "1.2.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": {