Skip to content

Commit

Permalink
Merge pull request #376 from tigrisdata/main
Browse files Browse the repository at this point in the history
Merged by Reviewpad
  • Loading branch information
reviewpad[bot] authored May 18, 2023
2 parents 4926217 + 267e12d commit ffe5d79
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
46 changes: 46 additions & 0 deletions src/__tests__/tigris.filters.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,40 @@ describe("filters tests", () => {
);
});

it("filter with an array value on array field", () => {
const arrayFilter: Filter<IUser1> = {
tags: ["tag1"],
};
expect(Utility.filterToString(arrayFilter)).toBe('{"tags":["tag1"]}');
});

it("filter with a string value on array field", () => {
const arrayFilter: Filter<IUser1> = {
tags: "tag1",
};
expect(Utility.filterToString(arrayFilter)).toBe('{"tags":"tag1"}');
});

it("filter with an array value on array of objects", () => {
const arrayFilter: Filter<IUser1> = {
address: [
{
city: "city1",
},
],
};
expect(Utility.filterToString(arrayFilter)).toBe('{"address":[{"city":"city1"}]}');
});

it("filter with an object value on array of objects", () => {
const arrayFilter: Filter<IUser1> = {
address: {
city: "city1",
},
};
expect(Utility.filterToString(arrayFilter)).toBe('{"address":{"city":"city1"}}');
});

it("simplerSelectorWithinLogicalFilterTest", () => {
const filter1: Filter<IUser> = {
$and: [
Expand Down Expand Up @@ -285,6 +319,14 @@ export interface IUser extends TigrisCollectionType {
balance: number;
}

export class UserAddress {
street: string;
unit: string;
city: string;
state: string;
zipcode: number;
}

@TigrisCollection("user1")
export class IUser1 {
@PrimaryKey({ order: 1 })
Expand All @@ -299,6 +341,10 @@ export class IUser1 {
createdAt: string;
@Field()
updatedAt: Date;
@Field({ elements: TigrisDataTypes.STRING })
tags: string[];
@Field({ elements: UserAddress })
address: UserAddress[];
}

export interface IUser2 extends TigrisCollectionType {
Expand Down
6 changes: 5 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,11 @@ export type SelectorOperator =
export type LogicalOperator = "$or" | "$and";

export type SelectorFilter<T> = {
[K in DocumentPaths<T>]?: PathType<T, K> | { [P in SelectorOperator]?: PathType<T, K> };
[K in DocumentPaths<T>]?:
| PathType<T, K>
| { [P in SelectorOperator]?: PathType<T, K> }
| FieldTypes
| { [P in SelectorOperator]?: FieldTypes };
};

export type LogicalFilter<T> = {
Expand Down

0 comments on commit ffe5d79

Please sign in to comment.