-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.d.ts
53 lines (44 loc) · 1.49 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import type { FastifyPluginCallback } from 'fastify'
import type { TypedDocument, insert, Orama, Results, SearchParams, create, AnyOrama, PartialSchemaDeep, Schema } from '@orama/orama'
interface FastifyOramaPersistence<T = any, O = any> {
restore: () => Promise<Orama<T> | null>
persist: (data: Orama<T>) => Promise<O>
}
declare class PersistenceInMemory<T = any, O = string | Buffer> implements FastifyOramaPersistence<T, O> {
constructor(options?: {
jsonIndex?: string,
})
restore: () => Promise<Orama<T> | null>
persist: (data: Orama<T>) => Promise<O>
}
declare class PersistenceInFile<T = any, O = string> implements FastifyOramaPersistence<T, O> {
constructor(options?: {
filePath?: string,
format?: string,
mustExistOnStart?: boolean
})
restore: () => Promise<Orama<T> | null>
persist: (data: Orama<T>) => Promise<O>
}
type FastifyOramaPluginOptions = {
persistence?: FastifyOramaPersistence
} & Partial<Parameters<typeof create>[0]>
declare const fastifyOrama: FastifyPluginCallback<FastifyOramaPluginOptions>
interface OramaApi<T> {
insert: (document: PartialSchemaDeep<TypedDocument<Orama<T>>>) => Promise<string>,
search: (params: SearchParams<Orama<Schema<T>>, T>) => Promise<Results<Schema<T>>>,
persist?: () => Promise<any>,
}
declare module 'fastify' {
interface FastifyInstance {
withOrama<T>(): this & {
orama: OramaApi<T>
};
}
}
export { fastifyOrama as default }
export {
fastifyOrama,
PersistenceInMemory,
PersistenceInFile
}