-
Notifications
You must be signed in to change notification settings - Fork 9
/
Model.d.ts
59 lines (42 loc) · 1.69 KB
/
Model.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
54
55
56
57
58
59
import RealmQuery from './libs/query'
import * as Realm from 'realm'
interface SearchOption {
stringFields?: string[]
limit?: number,
casing?: boolean
}
interface SearchOptionQuery extends SearchOption{
return: true
}
type NonFunctionPropertyNames<T> = { [K in keyof T]: T[K] extends Function ? never : K }[keyof Partial<T>];
type NonFunctionProperties<T> = Pick<Partial<T>, NonFunctionPropertyNames<T>>;
export default abstract class Model<M> extends Realm.Object<M> {
static schema: Realm.ObjectSchema
// @ts-ignore
static all<T extends M>(): Realm.Results<T>
// @ts-ignore
static searchText<T extends M>(term: string, limit?: number): Realm.Results<T>
// @ts-ignore
static searchText<T extends M>(term: string, limit?: boolean): RealmQuery<T>
// @ts-ignore
static searchText<T extends M>(term: string, options: SearchOptionQuery): RealmQuery<T>
// @ts-ignore
static searchText<T extends M>(term: string, options: SearchOption): Realm.Results<T>
// @ts-ignore
static find<T extends M>(id: number | string): T
// @ts-ignore
static query<T extends M>(): RealmQuery<T>
// @ts-ignore
static insert<T extends M>(object: NonFunctionProperties<T> | NonFunctionProperties<T>[]): Promise<void>
// @ts-ignore
static create<T extends M>(object: NonFunctionProperties<T> | NonFunctionProperties<T>[]): Promise<T>
static ids(): number[]
// @ts-ignore
static delete<T extends M>(object: Realm.Results<T> | T): Promise<void>
// @ts-ignore
static transform(data: any): any
// @ts-ignore
static syncObject(data: any): any
delete(): Promise<void>
update(object: NonFunctionProperties<M>): Promise<void>
}