-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathrx-collection.d.ts
119 lines (107 loc) · 4.18 KB
/
rx-collection.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import type {
RxJsonSchema,
RxDocument,
MigrationStrategies,
RxConflictHandler
} from './index.d.ts';
import type {
RxCollectionBase
} from '../rx-collection.d.ts';
import type { QueryCache } from '../query-cache.d.ts';
import type { RxLocalDocumentMutation } from './rx-database.d.ts';
export interface KeyFunctionMap {
[key: string]: Function;
}
export interface NumberFunctionMap {
[key: number]: Function;
}
/**
* Params to create a new collection.
* Notice the name of the collection is set one level higher
* when calling addCollections()
*/
export type RxCollectionCreator<RxDocType = any> = {
schema: RxJsonSchema<RxDocType>;
instanceCreationOptions?: any;
migrationStrategies?: MigrationStrategies;
autoMigrate?: boolean;
statics?: KeyFunctionMap;
methods?: KeyFunctionMap;
attachments?: KeyFunctionMap;
options?: any;
/**
* Set this to true if you want to store local documents
* in the RxCollection instance.
*/
localDocuments?: boolean;
cacheReplacementPolicy?: RxCacheReplacementPolicy;
/**
* Depending on which plugins or storage is used,
* the RxCollection might need a way to resolve conflicts
* which is done by this conflict handler.
* If no conflict handler is provided, a master-always-wins handler
* will be used as default
*/
conflictHandler?: RxConflictHandler<RxDocType>;
};
export type RxCacheReplacementPolicy = (collection: RxCollection, queryCache: QueryCache) => void;
export type RxCollectionHookCallback<
RxDocumentType,
OrmMethods,
Reactivity
> = (
data: RxDocumentType,
instance: RxDocument<RxDocumentType, OrmMethods, Reactivity>
) => void | Promise<void> | any;
export type RxCollectionHookNoInstance<RxDocumentType> = (data: RxDocumentType) => void | Promise<void> | any;
export type RxCollectionHookCallbackNonAsync<RxDocumentType, OrmMethods, Reactivity> = (
data: RxDocumentType,
instance: RxDocument<RxDocumentType, OrmMethods, Reactivity>
) => void | any;
export type RxCollectionHookNoInstanceCallback<
RxDocumentType,
OrmMethods,
Reactivity
> = (
data: RxDocumentType,
instance: RxCollection<RxDocumentType, OrmMethods, Reactivity>
) => Promise<void> | void | any;
export type RxCollection<
RxDocumentType = any,
OrmMethods = {},
StaticMethods = {},
InstanceCreationOptions = {},
Reactivity = unknown
> = StaticMethods &
RxCollectionBase<InstanceCreationOptions, RxDocumentType, OrmMethods, Reactivity> &
RxCollectionGenerated<RxDocumentType, OrmMethods, Reactivity>;
export interface RxCollectionGenerated<RxDocumentType = any, OrmMethods = {}, Reactivity = unknown> extends RxLocalDocumentMutation<RxCollection<RxDocumentType, OrmMethods, any, any, Reactivity>> {
// HOOKS
preInsert(fun: RxCollectionHookNoInstanceCallback<RxDocumentType, OrmMethods, Reactivity>, parallel: boolean): void;
preSave(fun: RxCollectionHookCallback<RxDocumentType, OrmMethods, Reactivity>, parallel: boolean): void;
preRemove(fun: RxCollectionHookCallback<RxDocumentType, OrmMethods, Reactivity>, parallel: boolean): void;
postInsert(fun: RxCollectionHookCallback<RxDocumentType, OrmMethods, Reactivity>, parallel: boolean): void;
postSave(fun: RxCollectionHookCallback<RxDocumentType, OrmMethods, Reactivity>, parallel: boolean): void;
postRemove(fun: RxCollectionHookCallback<RxDocumentType, OrmMethods, Reactivity>, parallel: boolean): void;
postCreate(fun: RxCollectionHookCallbackNonAsync<RxDocumentType, OrmMethods, Reactivity>): void;
// only inMemory-collections
awaitPersistence(): Promise<void>;
}
/**
* Properties are possibly encrypted so type them as any. TODO this is no longer needed.
*/
export type RxDumpCollectionAsAny<T> = { [P in keyof T]: any };
interface RxDumpCollectionBase {
name: string;
passwordHash?: string;
schemaHash: string;
}
export interface RxDumpCollection<RxDocumentType> extends RxDumpCollectionBase {
docs: RxDocumentType[];
}
/**
* All base properties are typed as any because they can be encrypted.
*/
export interface RxDumpCollectionAny<RxDocumentType> extends RxDumpCollectionBase {
docs: RxDumpCollectionAsAny<RxDocumentType>[];
}