Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add types for highlight object directly in search response #1362

Closed
mkurczewski opened this issue Feb 9, 2024 · 0 comments · Fixed by #1364
Closed

Add types for highlight object directly in search response #1362

mkurczewski opened this issue Feb 9, 2024 · 0 comments · Fixed by #1364
Assignees
Labels
bug Something isn't working needs-triage

Comments

@mkurczewski
Copy link

Describe the bug

The xata object for records returned using search API has still a standard XataRecordMetadata type:

type XataRecordMetadata = {
    /**
     * Number that is increased every time the record is updated.
     */
    version: number;
    /**
     * Timestamp when the record was created.
     */
    createdAt: Date;
    /**
     * Timestamp when the record was last updated.
     */
    updatedAt: Date;
};

There's no highlight or score options like in SearchExtraProperties type, although they are normally available in the code.

The only way to get it properly typed is to use the getMetadata() function on given record, however I can't see any reason why the xata object couldn't be typed directly.

To Reproduce

  1. Call a search function on any table, e.g.:
const results = await xataClient.db.someTable.search(phrase, {
    target: [
      { column: "someColumn" },
    ],
    fuzziness: 2,
    prefix: "phrase",
    highlight: {
      enabled: true,
      encodeHTML: true,
    },
  })
  1. Try to use highlight option later in the code:
console.log(results.records[0].xata.highlight)
  1. Observe a TS error:
TS2339: Property highlight does not exist on type XataRecordMetadata

Expected behavior

TypeScript knows that xata object for records returned by search function contains the same properties as defined in SearchExtraProperties type:

type SearchExtraProperties = {
    table: string;
    highlight?: {
        [key: string]: string[] | {
            [key: string]: any;
        };
    };
    score?: number;
};

Software version

"@xata.io/client": "^0.29.0"

Additional context

@mkurczewski mkurczewski added the bug Something isn't working label Feb 9, 2024
@SferaDev SferaDev self-assigned this Feb 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs-triage
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants