Skip to content

Commit

Permalink
feat: improves orama switch methods (#800)
Browse files Browse the repository at this point in the history
  • Loading branch information
micheleriva authored Sep 26, 2024
1 parent 463b6e0 commit ae4e129
Showing 1 changed file with 11 additions and 4 deletions.
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

0 comments on commit ae4e129

Please sign in to comment.