Skip to content

Commit

Permalink
fix(query): bug with query cloning
Browse files Browse the repository at this point in the history
  • Loading branch information
stdword committed Feb 19, 2024
1 parent 5bce93a commit af38b2a
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,16 +275,18 @@ export class PagesQueryBuilder {
if (message)
throw new Error(`${f}: ${message}`)

const [newVars, binders] = f.bindNewVars(this)
this.bindedVars.push(...newVars)
const clone = this.clone()

const [newVars, binders] = f.bindNewVars(clone)
clone.bindedVars.push(...newVars)

const predicate = [...binders]
const filterPredicate = nonInverted ? f.getPredicate(this) : f.getNotPredicate(this)
const filterPredicate = nonInverted ? f.getPredicate(clone) : f.getNotPredicate(clone)
if (filterPredicate)
predicate.push(filterPredicate)

this.filters.push(predicate.join('\n'))
return this.clone()
clone.filters.push(predicate.join('\n'))
return clone
}

title(operation: string, value: string = '', nonInverted: boolean = true) {
Expand Down Expand Up @@ -320,13 +322,13 @@ export class PagesQueryBuilder {
nonEmpty() {
return this._filter(new EmptyFilter(), false)
}
integerValue(operation: string, value: string = '', nonInverted: boolean = true) {
integerValue(operation: string, value: string = '') {
if (value === '') {
value = operation
operation = '='
}
value = value.toString()
return this._filter(new IntegerValueFilter(value, operation), nonInverted)
return this._filter(new IntegerValueFilter(value, operation))
}
value(operation: string, value: string = '', nonInverted: boolean = true) {
if (value === '') {
Expand All @@ -343,14 +345,13 @@ export class PagesQueryBuilder {
}
return this._filter(new ReferenceFilter(value, operation), nonInverted)
}

tags(names: string | string[] = '', only: boolean = false) {
this._filter(new PropertyFilter('tags'))
return this._filter(new ReferenceFilter(names, only ? 'includes only' : 'includes'))
const cloned = this._filter(new PropertyFilter('tags'))
return cloned._filter(new ReferenceFilter(names, only ? 'includes only' : 'includes'))
}
noTags(names: string | string[] = '', only: boolean = false) {
this._filter(new PropertyFilter('tags'))
return this._filter(new ReferenceFilter(names, only ? 'includes only' : 'includes'), false)
const cloned = this._filter(new PropertyFilter('tags'))
return cloned._filter(new ReferenceFilter(names, only ? 'includes only' : 'includes'), false)
}

_get(namesOnly: boolean = true): PageEntity[] {
Expand Down

0 comments on commit af38b2a

Please sign in to comment.