Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
chore: merge main into feat/nip-50-search
  • Loading branch information
Anshumancanrock committed Jun 21, 2026
commit ba853ccb00fe32656c248ef8ca214d5ceeb718a0
93 changes: 0 additions & 93 deletions src/repositories/event-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,99 +281,6 @@ export class EventRepository implements IEventRepository {
})
}

private applyHexFilterConditions(builder: any, currentFilter: SubscriptionFilter): void {
builder.andWhere((bd) => {
this.applyHexCriteria(bd, ['event_pubkey'], currentFilter.authors)
})

builder.andWhere((bd) => {
this.applyHexCriteria(bd, ['event_id'], currentFilter.ids)
})
}

private applyHexCriteria(builder: any, tableFields: string[], criteria?: string[]): void {
if (typeof criteria === 'undefined') {
return
}

if (!criteria.length) {
builder.whereRaw('1 = 0')
return
}

const groups = this.groupHexCriteria(criteria)

tableFields.forEach((tableField) => {
if (groups.exact.length) {
builder.orWhereIn(tableField, groups.exact.map(toBuffer))
}

groups.even.forEach((prefix) => {
builder.orWhereRaw(`substring("${tableField}" from 1 for ?) = ?`, [prefix.length >> 1, toBuffer(prefix)])
})

groups.odd.forEach((prefix) => {
builder.orWhereRaw(`substring("${tableField}" from 1 for ?) BETWEEN ? AND ?`, [
(prefix.length >> 1) + 1,
`\\x${prefix}0`,
`\\x${prefix}f`,
])
})
})
}

private groupHexCriteria(criteria: string[]): HexCriterionGroups {
return criteria.reduce<HexCriterionGroups>(
(groups, criterion) => {
if (criterion.length === 64) {
groups.exact.push(criterion)
} else if (criterion.length % 2 === 0) {
groups.even.push(criterion)
} else {
groups.odd.push(criterion)
}

return groups
},
{
exact: [],
even: [],
odd: [],
},
)
}

private applyGenericTagFilterConditions(builder: any, currentFilter: SubscriptionFilter): boolean {
const tagFilters = Object.entries(currentFilter).filter(([filterName]) => isGenericTagQuery(filterName))

tagFilters.forEach(([filterName, criteria]) => {
this.applyGenericTagCriteria(builder, filterName, criteria as string[])
})

return tagFilters.length > 0
}

private applyGenericTagCriteria(builder: any, filterName: string, criteria: string[]): void {
builder.andWhere((bd) => {
if (!criteria.length) {
bd.andWhereRaw('1 = 0')
return
}

criteria.forEach((criterion) => {
if (isGeohashPrefixCriterion(filterName, criterion)) {
bd.orWhereRaw('event_tags.tag_name = ? AND event_tags.tag_value LIKE ?', [
filterName[1],
`${stripGeohashPrefixWildcard(criterion)}%`,
])
return
}

bd.orWhereRaw('event_tags.tag_name = ? AND event_tags.tag_value = ?', [filterName[1], criterion])
})
})
}

public async create(event: Event): Promise<number> {
return this.insert(event).then(prop('rowCount') as () => number, () => 0)
}
Expand Down
1 change: 0 additions & 1 deletion src/routes/callbacks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,3 @@ router
)

export default router

44 changes: 0 additions & 44 deletions test/unit/schemas/filter-schema.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,47 +230,3 @@ describe('NIP-12', () => {
})
})
})

describe('NIP-12', () => {
describe('#g filter validation', () => {
it('accepts a valid base32 geohash', () => {
const result = validateSchema(filterSchema)({ '#g': ['u4pruydqqvj'] })
expect(result.error).to.be.undefined
})

it('accepts a valid geohash prefix with trailing wildcard', () => {
const result = validateSchema(filterSchema)({ '#g': ['u4pruyd*'] })
expect(result.error).to.be.undefined
})

it('rejects an empty criterion', () => {
const result = validateSchema(filterSchema)({ '#g': [''] })
expect(result.error).to.not.be.undefined
})

it('rejects a bare wildcard', () => {
const result = validateSchema(filterSchema)({ '#g': ['*'] })
expect(result.error).to.not.be.undefined
})

it('rejects non-base32 characters', () => {
const result = validateSchema(filterSchema)({ '#g': ['u4pruyda'] })
expect(result.error).to.not.be.undefined
})

it('rejects uppercase characters', () => {
const result = validateSchema(filterSchema)({ '#g': ['U4PRUYDQQVJ'] })
expect(result.error).to.not.be.undefined
})

it('rejects wildcard not at the end', () => {
const result = validateSchema(filterSchema)({ '#g': ['u4*pruyd'] })
expect(result.error).to.not.be.undefined
})

it('rejects multiple wildcards', () => {
const result = validateSchema(filterSchema)({ '#g': ['u4pruyd**'] })
expect(result.error).to.not.be.undefined
})
})
})
You are viewing a condensed version of this merge commit. You can view the full changes here.