Skip to content

Commit fa05418

Browse files
committed
feat: Improve Typing and create an Action Type for each transformation possible with the Schema
- Add documentation
1 parent 55e151c commit fa05418

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

src/morphism.ts

+18-7
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,24 @@ function zipObject(props: string[], values: any[]) {
6565
return { ...prev, [prop]: values[i] };
6666
}, {});
6767
}
68-
export type Many<T> = T | T[];
69-
export interface Schema {
70-
[targetProperty: string]:
71-
| string
72-
| ((iteratee: Many<object>, source: Many<object>, target: any) => any)
73-
| string[]
74-
| { path: string | string[]; fn: (fieldValue: Many<object>, items: Many<object>) => any };
68+
69+
type ActionString = string;
70+
interface ActionFunction {
71+
/**
72+
* A Function invoked per iteration
73+
*
74+
* @param {any} iteratee The current element to transform
75+
* @param {any} source The source input to transform
76+
* @param {any} target The current element transformed
77+
*
78+
*/
79+
(iteratee: any, source: any | any[], target: any): any;
80+
}
81+
type ActionAggregator = string[];
82+
type ActionSelector = { path: string | string[]; fn: (fieldValue: any, items: any[]) => any };
83+
84+
interface Schema {
85+
[targetProperty: string]: ActionString | ActionFunction | ActionAggregator | ActionSelector;
7586
}
7687

7788
/**

0 commit comments

Comments
 (0)