Skip to content
Draft
Show file tree
Hide file tree
Changes from 4 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
5 changes: 5 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ jobs:
- name: Install mobile dependencies
run: npm --prefix ui/mobile ci --ignore-scripts

- name: Verify TypeScript toolchains
run: |
npm run type-check:versions
npm --prefix ui/mobile run type-check:versions

- name: Setup Deno
uses: denoland/setup-deno@667a34cdef165d8d2b2e98dde39547c9daac7282 # v2.0.4
with:
Expand Down
2 changes: 2 additions & 0 deletions core/services/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ export class SearchService {
const normalizedRows: FtsSearchResult[] = rows.map((row) => ({
...(row as unknown as Tables<'notes'>),
user_id: userId,
tags: row.tags ?? [],
updated_at: row.updated_at ?? row.created_at ?? '',
description:
(row as unknown as { description?: string | null }).description ??
(row as unknown as { content?: string | null }).content ??
Expand Down
1 change: 0 additions & 1 deletion core/tests/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"extends": "../tsconfig.json",
"compilerOptions": {
"types": ["jest", "node"],
"baseUrl": ".",
"paths": {
"@core/*": ["../*"],
"@/supabase/*": ["../../supabase/*"],
Expand Down
39 changes: 35 additions & 4 deletions core/tests/unit/search-service-additional-branches.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ describe('SearchService additional branches', () => {
it('normalizes missing description, content and headline fields in FTS rows', async () => {
const rpc = jest.fn().mockResolvedValue({
data: [
{ id: 'missing-fields', rank: 0.2, description: null, content: null },
{ id: 'content-only', rank: 0.3, description: null, content: 'content fallback', headline: null, total_count: 2 },
{ id: 'missing-fields', rank: 0.2, description: null, content: null, created_at: '2024-01-01T00:00:00Z' },
{ id: 'content-only', rank: 0.3, description: null, content: 'content fallback', headline: null, total_count: 2, created_at: '2024-01-02T00:00:00Z' },
],
error: null,
})
Expand All @@ -61,8 +61,26 @@ describe('SearchService additional branches', () => {
method: 'fts',
total: 2,
results: [
{ id: 'missing-fields', user_id: 'user-1', description: '', content: null, headline: null, rank: 0.2 },
{ id: 'content-only', user_id: 'user-1', description: 'content fallback', content: 'content fallback', headline: null, rank: 0.3 },
{
id: 'missing-fields',
user_id: 'user-1',
description: '',
content: null,
headline: null,
rank: 0.2,
tags: [],
updated_at: '2024-01-01T00:00:00Z',
},
{
id: 'content-only',
user_id: 'user-1',
description: 'content fallback',
content: 'content fallback',
headline: null,
rank: 0.3,
tags: [],
updated_at: '2024-01-02T00:00:00Z',
},
],
})
})
Expand Down Expand Up @@ -91,6 +109,19 @@ describe('SearchService additional branches', () => {
})
})

it('normalizes missing fallback tags and updated_at', async () => {
const rpc = jest.fn().mockResolvedValue({ data: [], error: null })
const chain = createFallbackChain([
{ id: 'note-1', title: 'Title', description: 'Description', created_at: '2024-01-01T00:00:00Z' },
])
const service = createService(rpc, chain)

await expect(service.searchNotes('user-1', 'title')).resolves.toMatchObject({
method: 'fallback',
results: [{ id: 'note-1', tags: [], updated_at: '2024-01-01T00:00:00Z' }],
})
})

it('sends the exact REST fallback chain payload, including sanitized query and tag', async () => {
const rpc = jest.fn().mockResolvedValue({ data: [], error: null })
const chain = createFallbackChain([
Expand Down
2 changes: 2 additions & 0 deletions core/tests/unit/settings-search-additional-branches.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ describe("additional settings and search branches", () => {
title: "Title",
user_id: "user-1",
description: "",
tags: [],
updated_at: "",
rank: 0.7,
headline: null,
content: null,
Expand Down
2 changes: 1 addition & 1 deletion core/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "../tsconfig.base.json",
"compilerOptions": {
"baseUrl": ".",
"types": ["node"],
"paths": {
"@core/*": [
"./*"
Expand Down
8 changes: 7 additions & 1 deletion core/utils/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,15 @@ export type SearchResult = {

export type NotesTable = Tables<'notes'>

const normalizeSearchNote = (note: NotesTable): NotesTable => ({
...note,
tags: note.tags ?? [],
updated_at: note.updated_at ?? note.created_at ?? '',
})

export const mapNotesToFtsResult = (notes: NotesTable[], userId: string): FtsSearchResult[] =>
notes.map((note) => ({
...note,
...normalizeSearchNote(note),
user_id: userId,
rank: 0,
headline: note.description ? note.description.substring(0, 200) : '',
Expand Down
Loading
Loading