Skip to content

Commit 7ef14d2

Browse files
committed
feat(schema): possible now to use ActionSelector without fn callback
1 parent 6fa52a3 commit 7ef14d2

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

src/MorphismTree.ts

-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ export class MorphismSchemaTree<Target, Source> {
151151
queue.push(this.root);
152152
while (queue.length > 0) {
153153
let node = queue.shift();
154-
155154
if (node) {
156155
for (let i = 0, length = node.children.length; i < length; i++) {
157156
queue.push(node.children[i]);

src/helpers.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { ActionSelector, ActionAggregator, ActionFunction } from './types';
1515
export const SCHEMA_OPTIONS_SYMBOL = Symbol('SchemaOptions');
1616

1717
export function isActionSelector<S, R>(value: any): value is ActionSelector<S, R> {
18-
return isObject(value) && value.hasOwnProperty('fn') && value.hasOwnProperty('path');
18+
return isObject(value) && (value.hasOwnProperty('fn') || value.hasOwnProperty('path'));
1919
}
2020
export function isActionString(value: any): value is string {
2121
return isString(value);

src/morphism.spec.ts

+11
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,17 @@ describe('Morphism', () => {
328328
let results = Morphism(schema, dataToCrunch);
329329
expect(results[0]).toEqual(desiredResult);
330330
});
331+
it('should allow to use an action selector without a `fn` specified', () => {
332+
interface Source {
333+
s1: string;
334+
}
335+
interface Target {
336+
t1: string;
337+
}
338+
const schema = createSchema<Target, Source>({ t1: { path: 's1' } });
339+
const result = morphism(schema, { s1: 'value' });
340+
expect(result.t1).toEqual('value');
341+
});
331342
});
332343
describe('Function Predicate', function() {
333344
it('should support es6 destructuring as function predicate', function() {

0 commit comments

Comments
 (0)