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

feat: improves orama switch methods #800

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Changes from all 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
15 changes: 11 additions & 4 deletions packages/switch/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@ import type { AnyOrama, Results, SearchParams, Nullable } from '@orama/orama'
import { search } from '@orama/orama'
import { OramaClient, ClientSearchParams } from '@oramacloud/client'

type OramaSwitchClient = AnyOrama | OramaClient
export type OramaSwitchClient = AnyOrama | OramaClient

type ClientType = 'oss' | 'cloud'
export type ClientType = 'oss' | 'cloud'

export type SearchConfig = {
abortController?: AbortController
fresh?: boolean
debounce?: number
}

export class Switch<T = OramaSwitchClient> {
client: OramaSwitchClient
Expand All @@ -27,10 +33,11 @@ export class Switch<T = OramaSwitchClient> {
}

async search<R = unknown>(
params: T extends OramaClient ? ClientSearchParams : SearchParams<AnyOrama>
params: T extends OramaClient ? ClientSearchParams : SearchParams<AnyOrama>,
config?: SearchConfig
): Promise<Nullable<Results<R>>> {
if (this.isCloud) {
return (this.client as OramaClient).search(params as T extends OramaClient ? ClientSearchParams : never)
return (this.client as OramaClient).search(params as T extends OramaClient ? ClientSearchParams : never, config)
} else {
return search(this.client as AnyOrama, params as SearchParams<AnyOrama>) as Promise<Nullable<Results<R>>>
}
Expand Down
Loading