Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions src/collections/filters/classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ export class FilterBase {
: undefined,
});
}

let target = this.target;
while (target.target !== undefined) {
if (TargetGuards.isTargetRef(target.target)) {
Expand Down Expand Up @@ -222,32 +221,32 @@ export class FilterRef<T> implements Filter<T> {

public byRef<K extends RefKeys<T> & string>(linkOn: K): Filter<ExtractCrossReferenceType<T[K]>> {
this.target.target = { type_: 'single', linkOn: linkOn };
return new FilterRef<ExtractCrossReferenceType<T[K]>>(this.target);
return new FilterRef<ExtractCrossReferenceType<T[K]>>(Object.assign({}, this.target));
}

public byRefMultiTarget<K extends RefKeys<T> & string>(linkOn: K, targetCollection: string) {
this.target.target = { type_: 'multi', linkOn: linkOn, targetCollection: targetCollection };
return new FilterRef<ExtractCrossReferenceType<T[K]>>(this.target);
return new FilterRef<ExtractCrossReferenceType<T[K]>>(Object.assign({}, this.target));
}

public byProperty<K extends NonRefKeys<T> & string>(name: K, length = false) {
return new FilterProperty<T[K]>(name, length, this.target);
return new FilterProperty<T[K]>(name, length, Object.assign({}, this.target));
}

public byRefCount<K extends RefKeys<T> & string>(linkOn: K) {
return new FilterCount(linkOn, this.target);
return new FilterCount(linkOn, Object.assign({}, this.target));
}

public byId() {
return new FilterId(this.target);
return new FilterId(Object.assign({}, this.target));
}

public byCreationTime() {
return new FilterCreationTime(this.target);
return new FilterCreationTime(Object.assign({}, this.target));
}

public byUpdateTime() {
return new FilterUpdateTime(this.target);
return new FilterUpdateTime(Object.assign({}, this.target));
}
}

Expand Down
30 changes: 30 additions & 0 deletions src/collections/filters/unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,36 @@ describe('Unit testing of filters', () => {
});
});

it('should create two filters through a single ref used multiple times', () => {
const f = filter.byRef('self');
const f1 = f.byProperty('name').equal('Jim');
const f2 = f.byProperty('name').equal('Bob');
expect(f1).toEqual<FilterValue<string>>({
operator: 'Equal',
target: {
singleTarget: {
on: 'self',
target: {
property: 'name',
},
},
},
value: 'Jim',
});
expect(f2).toEqual<FilterValue<string>>({
operator: 'Equal',
target: {
singleTarget: {
on: 'self',
target: {
property: 'name',
},
},
},
value: 'Bob',
});
});

it('should create a nested reference filter', () => {
const f = filter.byRef('self').byRef('self').byProperty('name').isNull(true);
expect(f).toEqual<FilterValue<boolean>>({
Expand Down