Skip to content

Commit

Permalink
feat: update types to handle basic types to validate
Browse files Browse the repository at this point in the history
  • Loading branch information
emyann committed Jun 22, 2019
1 parent 62d27e7 commit 9f469e5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/morphism.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function transformItems<T, TSchema extends Schema<T | {}>>(schema: TSchema, type
tree = new MorphismSchemaTree(schema);
}

function mapper(source: any) {
const mapper: Mapper<TSchema> = (source: any) => {
if (!source) {
return source;
}
Expand All @@ -96,7 +96,7 @@ function transformItems<T, TSchema extends Schema<T | {}>>(schema: TSchema, type
return transformValuesFromObject(object, tree, [object], jsObject);
}
}
}
};

return mapper;
}
Expand Down
9 changes: 6 additions & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { SCHEMA_OPTIONS_SYMBOL, SchemaOptions } from './morphism';
import { BasicTypes } from './validation/validators';

/**
* A structure-preserving object from a source data towards a target data.
Expand Down Expand Up @@ -159,7 +160,9 @@ export type ActionAggregator<T extends unknown = unknown> = T extends object ? (
*/
export interface ActionSelector<Source = object, R = any> {
path: ActionString<Source> | ActionAggregator<Source>;
fn: (fieldValue: any, object: Source, items: Source, objectToCompute: R) => R;
// | ((source: Source) => unknown);
fn?: (fieldValue: any, object: Source, items: Source, objectToCompute: R) => R;
type?: BasicTypes;
}

export interface Constructable<T> {
Expand All @@ -172,6 +175,6 @@ export type DestinationFromSchema<T> = T extends StrictSchema<infer U> | Schema<
export type ResultItem<TSchema extends Schema> = DestinationFromSchema<TSchema>;

export interface Mapper<TSchema extends Schema | StrictSchema, TResult = ResultItem<TSchema>> {
(data: SourceFromSchema<TSchema>[]): TResult[];
(data: SourceFromSchema<TSchema>): TResult;
(data?: SourceFromSchema<TSchema>[] | null): TResult[];
(data?: SourceFromSchema<TSchema> | null): TResult;
}

0 comments on commit 9f469e5

Please sign in to comment.