Skip to content

Commit

Permalink
Always return new instance
Browse files Browse the repository at this point in the history
  • Loading branch information
gksander committed Aug 4, 2023
1 parent bf32fda commit 749dd34
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/moody-spoons-thank.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"groqd": patch
---

Always return a new Class from builder methods, addresses #204.
18 changes: 12 additions & 6 deletions packages/groqd/src/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,10 @@ export class ArrayQuery<T extends z.ZodTypeAny> extends BaseQuery<
}

filter(filterValue = "") {
this.query += `[${filterValue}]`;
return this;
return new ArrayQuery<T>({
...this.value(),
query: this.query + `[${filterValue}]`,
});
}

filterByType(filterTypeValue: string) {
Expand Down Expand Up @@ -200,13 +202,17 @@ export class ArrayQuery<T extends z.ZodTypeAny> extends BaseQuery<
}

order(...orderings: `${string} ${"asc" | "desc"}`[]): ArrayQuery<T> {
this.query += `|order(${orderings.join(", ")})`;
return this;
return new ArrayQuery<T>({
...this.value(),
query: this.query + `|order(${orderings.join(", ")})`,
});
}

score(...scores: string[]): ArrayQuery<T> {
this.query += `|score(${scores.join(", ")})`;
return this;
return new ArrayQuery<T>({
...this.value(),
query: this.query + `|score(${scores.join(", ")})`,
});
}

// Slicing
Expand Down

0 comments on commit 749dd34

Please sign in to comment.