@connecttomahdi/rxdb 17.1.0 → 17.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/plugins/storage-dexie/rx-storage-instance-dexie.js +10 -10
- package/dist/cjs/plugins/storage-dexie/rx-storage-instance-dexie.js.map +1 -1
- package/dist/cjs/plugins/utils/utils-premium.js +4 -4
- package/dist/cjs/plugins/utils/utils-premium.js.map +1 -1
- package/dist/esm/package.json +1 -0
- package/dist/esm/plugins/storage-dexie/rx-storage-instance-dexie.js +10 -10
- package/dist/esm/plugins/storage-dexie/rx-storage-instance-dexie.js.map +1 -1
- package/dist/esm/plugins/utils/utils-premium.js +4 -4
- package/dist/esm/plugins/utils/utils-premium.js.map +1 -1
- package/dist/types/index.d.ts +26 -25
- package/dist/types/types/conflict-handling.d.ts +48 -0
- package/dist/types/types/couchdb.d.ts +293 -0
- package/dist/types/types/index.d.ts +32 -0
- package/dist/types/types/modules/index.d.ts +0 -0
- package/dist/types/types/modules/mocha.parallel.d.ts +1 -0
- package/dist/types/types/plugins/backup.d.ts +35 -0
- package/dist/types/types/plugins/cleanup.d.ts +38 -0
- package/dist/types/types/plugins/crdt.d.ts +76 -0
- package/dist/types/types/plugins/dexie.d.ts +30 -0
- package/dist/types/types/plugins/local-documents.d.ts +49 -0
- package/dist/types/types/plugins/migration.d.ts +14 -0
- package/dist/types/types/plugins/reactivity.d.ts +40 -0
- package/dist/types/types/plugins/replication-graphql.d.ts +98 -0
- package/dist/types/types/plugins/replication.d.ts +175 -0
- package/dist/types/types/plugins/state.d.ts +4 -0
- package/dist/types/types/plugins/update.d.ts +23 -0
- package/dist/types/types/plugins/webmcp.d.ts +40 -0
- package/dist/types/types/query-planner.d.ts +47 -0
- package/dist/types/types/replication-protocol.d.ts +296 -0
- package/dist/types/types/rx-attachment.d.ts +46 -0
- package/dist/types/types/rx-change-event.d.ts +85 -0
- package/dist/types/types/rx-collection.d.ts +117 -0
- package/dist/types/types/rx-database-internal-store.d.ts +54 -0
- package/dist/types/types/rx-database.d.ts +124 -0
- package/dist/types/types/rx-document.d.ts +160 -0
- package/dist/types/types/rx-error.d.ts +225 -0
- package/dist/types/types/rx-plugin.d.ts +167 -0
- package/dist/types/types/rx-query.d.ts +144 -0
- package/dist/types/types/rx-schema.d.ts +214 -0
- package/dist/types/types/rx-storage.d.ts +347 -0
- package/dist/types/types/rx-storage.interface.d.ts +312 -0
- package/dist/types/types/util.d.ts +180 -0
- package/package.json +732 -732
- package/scripts/copy-path.mjs +20 -0
- package/scripts/fix-types.mjs +15 -8
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import type { RxJsonSchema } from './rx-schema.d.ts';
|
|
2
|
+
import {
|
|
3
|
+
RxSchema
|
|
4
|
+
} from '../rx-schema.ts';
|
|
5
|
+
import type { RxPlugin } from './rx-plugin.d.ts';
|
|
6
|
+
import { ERROR_MESSAGES } from '../plugins/dev-mode/error-messages.ts';
|
|
7
|
+
import type { RxReplicationWriteToMasterRow } from './replication-protocol.d.ts';
|
|
8
|
+
import type { BulkWriteRow, RxDocumentData } from './rx-storage.d.ts';
|
|
9
|
+
|
|
10
|
+
type KeyOf<T extends object> = Extract<keyof T, string>;
|
|
11
|
+
export type RxErrorKey = KeyOf<typeof ERROR_MESSAGES>;
|
|
12
|
+
|
|
13
|
+
export type {
|
|
14
|
+
RxError,
|
|
15
|
+
RxTypeError
|
|
16
|
+
} from '../rx-error.ts';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* this lists all possible parameters
|
|
20
|
+
*/
|
|
21
|
+
export interface RxErrorParameters {
|
|
22
|
+
readonly error?: PlainJsonError;
|
|
23
|
+
readonly errors?: PlainJsonError[];
|
|
24
|
+
readonly errorText?: string;
|
|
25
|
+
readonly writeError?: RxStorageWriteError<any>;
|
|
26
|
+
readonly schemaPath?: string;
|
|
27
|
+
readonly objPath?: string;
|
|
28
|
+
readonly rootPath?: string;
|
|
29
|
+
readonly childpath?: string;
|
|
30
|
+
readonly ids?: string[];
|
|
31
|
+
readonly duplicateIds?: string[];
|
|
32
|
+
readonly obj?: any;
|
|
33
|
+
readonly document?: any;
|
|
34
|
+
readonly schema?: Readonly<RxJsonSchema<any> | RxSchema>;
|
|
35
|
+
readonly schemaObj?: any;
|
|
36
|
+
readonly pluginKey?: string;
|
|
37
|
+
readonly originalDoc?: Readonly<any>;
|
|
38
|
+
readonly finalDoc?: Readonly<any>;
|
|
39
|
+
readonly regex?: string;
|
|
40
|
+
readonly fieldName?: string;
|
|
41
|
+
readonly id?: string;
|
|
42
|
+
readonly documentId?: string;
|
|
43
|
+
readonly data?: any;
|
|
44
|
+
readonly missingCollections?: string[];
|
|
45
|
+
readonly primaryPath?: string;
|
|
46
|
+
readonly primary?: string;
|
|
47
|
+
readonly primaryKey?: string;
|
|
48
|
+
readonly have?: any;
|
|
49
|
+
readonly should?: any;
|
|
50
|
+
readonly name?: string;
|
|
51
|
+
readonly adapter?: any;
|
|
52
|
+
readonly link?: string;
|
|
53
|
+
readonly path?: string;
|
|
54
|
+
readonly value?: any;
|
|
55
|
+
readonly givenName?: string;
|
|
56
|
+
readonly fromVersion?: number;
|
|
57
|
+
readonly toVersion?: number;
|
|
58
|
+
readonly version?: number;
|
|
59
|
+
readonly args?: any;
|
|
60
|
+
readonly opts?: any;
|
|
61
|
+
readonly dataBefore?: any;
|
|
62
|
+
readonly dataAfter?: any;
|
|
63
|
+
readonly pull?: boolean;
|
|
64
|
+
readonly push?: boolean;
|
|
65
|
+
readonly url?: string;
|
|
66
|
+
readonly key?: string;
|
|
67
|
+
readonly queryObj?: any;
|
|
68
|
+
readonly query?: any;
|
|
69
|
+
readonly op?: string;
|
|
70
|
+
readonly skip?: any;
|
|
71
|
+
readonly limit?: any;
|
|
72
|
+
readonly passwordHash?: string;
|
|
73
|
+
readonly existingPasswordHash?: string;
|
|
74
|
+
readonly password?: string | any;
|
|
75
|
+
readonly passwordType?: string;
|
|
76
|
+
readonly passwordLength?: number;
|
|
77
|
+
readonly minPassLength?: number;
|
|
78
|
+
readonly own?: any;
|
|
79
|
+
readonly source?: any;
|
|
80
|
+
readonly method?: any;
|
|
81
|
+
readonly field?: string;
|
|
82
|
+
readonly ref?: string;
|
|
83
|
+
readonly funName?: string;
|
|
84
|
+
readonly functionName?: string;
|
|
85
|
+
readonly schemaHash?: string;
|
|
86
|
+
readonly previousSchema?: Readonly<RxJsonSchema<any>>;
|
|
87
|
+
readonly previousSchemaHash?: string;
|
|
88
|
+
readonly type?: string;
|
|
89
|
+
readonly when?: string;
|
|
90
|
+
readonly parallel?: boolean;
|
|
91
|
+
readonly collection?: any;
|
|
92
|
+
readonly database?: any;
|
|
93
|
+
readonly storage?: string;
|
|
94
|
+
readonly indexes?: Array<string | string[]> | Readonly<Array<string | string[]>>;
|
|
95
|
+
readonly index?: string | string[] | readonly string[];
|
|
96
|
+
readonly plugin?: RxPlugin | any;
|
|
97
|
+
readonly plugins?: Set<RxPlugin | any>;
|
|
98
|
+
|
|
99
|
+
// used in the replication plugin
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* The checkpoint of the response from the last successful
|
|
103
|
+
* pull by the client.
|
|
104
|
+
* Null if there was no pull operation before
|
|
105
|
+
* so that there is no last pulled checkpoint.
|
|
106
|
+
*/
|
|
107
|
+
readonly checkpoint?: any;
|
|
108
|
+
/**
|
|
109
|
+
* The documents that failed to be pushed.
|
|
110
|
+
* Typed as 'any' because they might be modified by the push modifier.
|
|
111
|
+
*/
|
|
112
|
+
readonly pushRows?: RxReplicationWriteToMasterRow<any>[];
|
|
113
|
+
readonly direction?: 'pull' | 'push';
|
|
114
|
+
|
|
115
|
+
// google-drive-replication
|
|
116
|
+
readonly folderPath?: string;
|
|
117
|
+
readonly folderName?: string;
|
|
118
|
+
readonly file?: any;
|
|
119
|
+
readonly parentId?: string;
|
|
120
|
+
|
|
121
|
+
// fetch
|
|
122
|
+
readonly body?: any;
|
|
123
|
+
readonly status?: number;
|
|
124
|
+
readonly statusText?: string;
|
|
125
|
+
readonly headers?: Record<string, any>;
|
|
126
|
+
readonly code?: string;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Error-Items which are created by the jsonschema-validator
|
|
131
|
+
*/
|
|
132
|
+
export type RxValidationError = {
|
|
133
|
+
readonly field: string;
|
|
134
|
+
readonly message: string;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Use to have a transferable error object
|
|
139
|
+
* in plain json instead of a JavaScript Error instance.
|
|
140
|
+
*/
|
|
141
|
+
export type PlainJsonError = {
|
|
142
|
+
name: string;
|
|
143
|
+
message: string;
|
|
144
|
+
rxdb?: true;
|
|
145
|
+
code?: RxErrorKey;
|
|
146
|
+
url?: string;
|
|
147
|
+
extensions?: Record<string, any>;
|
|
148
|
+
parameters?: RxErrorParameters;
|
|
149
|
+
stack?: string;
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Error that can happen per document when
|
|
158
|
+
* RxStorage.bulkWrite() is called
|
|
159
|
+
*/
|
|
160
|
+
export type RxStorageWriteErrorBase<RxDocType> = {
|
|
161
|
+
status: number
|
|
162
|
+
| 409 // conflict
|
|
163
|
+
| 422 // schema validation error
|
|
164
|
+
| 510 // attachment data missing
|
|
165
|
+
;
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* set this property to make it easy
|
|
169
|
+
* to detect if the object is a RxStorageBulkWriteError
|
|
170
|
+
*/
|
|
171
|
+
isError: true;
|
|
172
|
+
|
|
173
|
+
// primary key of the document
|
|
174
|
+
documentId: string;
|
|
175
|
+
|
|
176
|
+
// the original document data that should have been written.
|
|
177
|
+
writeRow: BulkWriteRow<RxDocType>;
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* The context which was given to bulkWrite(),
|
|
181
|
+
* used for debugging.
|
|
182
|
+
*/
|
|
183
|
+
context: string;
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
export type RxStorageWriteErrorConflict<RxDocType> = RxStorageWriteErrorBase<RxDocType> & {
|
|
187
|
+
status: 409;
|
|
188
|
+
/**
|
|
189
|
+
* A conflict error state must contain the
|
|
190
|
+
* document state in the database.
|
|
191
|
+
* This ensures that we can continue resolving a conflict
|
|
192
|
+
* without having to pull the document out of the db first.
|
|
193
|
+
* Is not set if the error happens on an insert.
|
|
194
|
+
*/
|
|
195
|
+
documentInDb: RxDocumentData<RxDocType>;
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
export type RxStorageWriteErrorValidation<RxDocType> = RxStorageWriteErrorBase<RxDocType> & {
|
|
199
|
+
status: 422;
|
|
200
|
+
/**
|
|
201
|
+
* Other properties that give
|
|
202
|
+
* information about the error,
|
|
203
|
+
* for example a schema validation error
|
|
204
|
+
* might contain the exact error from the validator here.
|
|
205
|
+
* Must be plain JSON!
|
|
206
|
+
*/
|
|
207
|
+
validationErrors: RxValidationError[];
|
|
208
|
+
/**
|
|
209
|
+
* For easier debugging,
|
|
210
|
+
* we directly put the schema into the error.
|
|
211
|
+
*/
|
|
212
|
+
schema: RxJsonSchema<RxDocumentData<RxDocType>>;
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
export type RxStorageWriteErrorAttachment<RxDocType> = RxStorageWriteErrorBase<RxDocType> & {
|
|
216
|
+
status: 510;
|
|
217
|
+
attachmentId: string;
|
|
218
|
+
documentInDb?: RxDocumentData<RxDocType>;
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
export type RxStorageWriteError<RxDocType> =
|
|
223
|
+
RxStorageWriteErrorConflict<RxDocType> |
|
|
224
|
+
RxStorageWriteErrorValidation<RxDocType> |
|
|
225
|
+
RxStorageWriteErrorAttachment<RxDocType>;
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
RxQuery,
|
|
3
|
+
RxQueryOP,
|
|
4
|
+
MangoQuery
|
|
5
|
+
} from './rx-query.d.ts';
|
|
6
|
+
import type {
|
|
7
|
+
RxCollection,
|
|
8
|
+
RxCollectionCreator
|
|
9
|
+
} from './rx-collection.d.ts';
|
|
10
|
+
import type {
|
|
11
|
+
RxStorageInstanceCreationParams
|
|
12
|
+
} from './rx-storage.d.ts';
|
|
13
|
+
import type {
|
|
14
|
+
DeepReadonly,
|
|
15
|
+
FilledMangoQuery,
|
|
16
|
+
RxDatabase,
|
|
17
|
+
RxDatabaseCreator,
|
|
18
|
+
RxDocument,
|
|
19
|
+
RxStorage,
|
|
20
|
+
RxReplicationWriteToMasterRow,
|
|
21
|
+
WithDeleted,
|
|
22
|
+
RxState,
|
|
23
|
+
BulkWriteRow,
|
|
24
|
+
RxStorageInstance
|
|
25
|
+
} from './index.d.ts';
|
|
26
|
+
import type { RxSchema } from '../rx-schema.d.ts';
|
|
27
|
+
|
|
28
|
+
export type RxPluginPrePrepareRxQueryArgs = {
|
|
29
|
+
op: RxQueryOP;
|
|
30
|
+
queryObj: MangoQuery | string | number | Array<any>;
|
|
31
|
+
collection: RxCollection;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export type RxPluginPreCreateRxQueryArgs = {
|
|
35
|
+
op: RxQueryOP;
|
|
36
|
+
queryObj: MangoQuery;
|
|
37
|
+
collection: RxCollection;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export type RxPluginPreAddRxPluginArgs = {
|
|
41
|
+
// the plugin that is getting added
|
|
42
|
+
plugin: RxPlugin | any;
|
|
43
|
+
// previous added plugins
|
|
44
|
+
plugins: Set<RxPlugin | any>;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export type RxPluginPrePrepareQueryArgs = {
|
|
48
|
+
rxQuery: RxQuery<any>;
|
|
49
|
+
mangoQuery: FilledMangoQuery<any>;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Depending on which plugins are used together,
|
|
55
|
+
* it is important that the plugin is able to define if
|
|
56
|
+
* the hooks must be added as first or as last array item.
|
|
57
|
+
* For example the encryption plugin must run encryption
|
|
58
|
+
* before the key-compression changes the fieldnames.
|
|
59
|
+
*/
|
|
60
|
+
export type RxPluginHooks<Input> = {
|
|
61
|
+
/**
|
|
62
|
+
* Hook function that is added as first.
|
|
63
|
+
*/
|
|
64
|
+
before?: (i: Input) => void;
|
|
65
|
+
/**
|
|
66
|
+
* Hook function that is added as last.
|
|
67
|
+
*/
|
|
68
|
+
after?: (i: Input) => void;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export interface RxPlugin {
|
|
72
|
+
/**
|
|
73
|
+
* A string to uniquely identifies the plugin.
|
|
74
|
+
* Can be used to throw when different versions of the same plugin are used.
|
|
75
|
+
* And also other checks.
|
|
76
|
+
* Use kebab-case.
|
|
77
|
+
*/
|
|
78
|
+
readonly name: string;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* set this to true so RxDB
|
|
82
|
+
* knows that this object in a rxdb plugin
|
|
83
|
+
*/
|
|
84
|
+
readonly rxdb: true;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Init function where dependent plugins could be added.
|
|
88
|
+
* (optional)
|
|
89
|
+
*/
|
|
90
|
+
init?(): any;
|
|
91
|
+
|
|
92
|
+
prototypes?: {
|
|
93
|
+
RxSchema?: (proto: RxSchema) => void;
|
|
94
|
+
RxDocument?: (proto: RxDocument) => void;
|
|
95
|
+
RxQuery?: (proto: RxQuery) => void;
|
|
96
|
+
RxCollection?: (proto: RxCollection) => void;
|
|
97
|
+
RxDatabase?: (proto: RxDatabase) => void;
|
|
98
|
+
};
|
|
99
|
+
overwritable?: {
|
|
100
|
+
isDevMode?: () => boolean;
|
|
101
|
+
deepFreezeWhenDevMode?: <T>(obj: T) => DeepReadonly<T>;
|
|
102
|
+
validatePassword?: Function;
|
|
103
|
+
checkAdapter?: Function;
|
|
104
|
+
tunnelErrorMessage?: Function;
|
|
105
|
+
};
|
|
106
|
+
hooks?: {
|
|
107
|
+
preAddRxPlugin?: RxPluginHooks<RxPluginPreAddRxPluginArgs>;
|
|
108
|
+
preCreateRxDatabase?: RxPluginHooks<any>;
|
|
109
|
+
createRxDatabase?: RxPluginHooks<{
|
|
110
|
+
database: RxDatabase;
|
|
111
|
+
creator: RxDatabaseCreator;
|
|
112
|
+
}>;
|
|
113
|
+
preCloseRxDatabase?: RxPluginHooks<RxDatabase>;
|
|
114
|
+
postRemoveRxDatabase?: RxPluginHooks<{
|
|
115
|
+
databaseName: string;
|
|
116
|
+
storage: RxStorage<any, any>;
|
|
117
|
+
}>;
|
|
118
|
+
createRxCollection?: RxPluginHooks<{
|
|
119
|
+
collection: RxCollection;
|
|
120
|
+
creator: RxCollectionCreator;
|
|
121
|
+
}>;
|
|
122
|
+
createRxState?: RxPluginHooks<{
|
|
123
|
+
collection: RxCollection;
|
|
124
|
+
state: RxState<unknown, unknown>;
|
|
125
|
+
}>;
|
|
126
|
+
preCreateRxCollection?: RxPluginHooks<RxCollectionCreator<any> & {
|
|
127
|
+
name: string;
|
|
128
|
+
database: RxDatabase;
|
|
129
|
+
}>;
|
|
130
|
+
postCloseRxCollection?: RxPluginHooks<RxCollection>;
|
|
131
|
+
postRemoveRxCollection?: RxPluginHooks<{
|
|
132
|
+
storage: RxStorage<any, any>;
|
|
133
|
+
databaseName: string;
|
|
134
|
+
collectionName: string;
|
|
135
|
+
}>;
|
|
136
|
+
preCreateRxSchema?: RxPluginHooks<any>;
|
|
137
|
+
createRxSchema?: RxPluginHooks<any>;
|
|
138
|
+
prePrepareRxQuery?: RxPluginHooks<RxPluginPrePrepareRxQueryArgs>;
|
|
139
|
+
preCreateRxQuery?: RxPluginHooks<RxPluginPreCreateRxQueryArgs>;
|
|
140
|
+
prePrepareQuery?: RxPluginHooks<RxPluginPrePrepareQueryArgs>;
|
|
141
|
+
createRxQuery?: RxPluginHooks<RxQuery>;
|
|
142
|
+
createRxDocument?: RxPluginHooks<any>;
|
|
143
|
+
postCreateRxDocument?: RxPluginHooks<any>;
|
|
144
|
+
preCreateRxStorageInstance?: RxPluginHooks<RxStorageInstanceCreationParams<any, any>>;
|
|
145
|
+
/**
|
|
146
|
+
* Runs before a write to the storage instance of a RxCollection or RxDatabase.
|
|
147
|
+
*/
|
|
148
|
+
preStorageWrite?: RxPluginHooks<{
|
|
149
|
+
storageInstance: RxStorageInstance<any, any, any, any>;
|
|
150
|
+
rows: BulkWriteRow<any>[];
|
|
151
|
+
}>;
|
|
152
|
+
preMigrateDocument?: RxPluginHooks<any>;
|
|
153
|
+
postMigrateDocument?: RxPluginHooks<any>;
|
|
154
|
+
postCleanup?: RxPluginHooks<{
|
|
155
|
+
databaseName: string;
|
|
156
|
+
collectionName: string;
|
|
157
|
+
}>;
|
|
158
|
+
preReplicationMasterWrite?: RxPluginHooks<{
|
|
159
|
+
rows: RxReplicationWriteToMasterRow<any>[];
|
|
160
|
+
collection: RxCollection;
|
|
161
|
+
}>;
|
|
162
|
+
preReplicationMasterWriteDocumentsHandle?: RxPluginHooks<{
|
|
163
|
+
result: WithDeleted<any>[];
|
|
164
|
+
collection: RxCollection;
|
|
165
|
+
}>;
|
|
166
|
+
};
|
|
167
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
RxQueryBase
|
|
3
|
+
} from '../rx-query.d.ts';
|
|
4
|
+
import type { Paths, StringKeys } from './util.d.ts';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Typed Mango Query Selector
|
|
8
|
+
* @link https://github.com/mongodb/node-mongodb-native/blob/26bce4a8debb65df5a42dc8599e886c9c83de10d/src/mongo_types.ts
|
|
9
|
+
* @link https://stackoverflow.com/a/58436959/3443137
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
export type PropertyType<Type, Property extends string> = string extends Property
|
|
14
|
+
? unknown
|
|
15
|
+
: Property extends keyof Type
|
|
16
|
+
? Type[Property]
|
|
17
|
+
: Property extends `${number}`
|
|
18
|
+
? Type extends ReadonlyArray<infer ArrayType>
|
|
19
|
+
? ArrayType
|
|
20
|
+
: unknown
|
|
21
|
+
: Property extends `${infer Key}.${infer Rest}`
|
|
22
|
+
? Key extends `${number}`
|
|
23
|
+
? Type extends ReadonlyArray<infer ArrayType>
|
|
24
|
+
? PropertyType<ArrayType, Rest>
|
|
25
|
+
: unknown
|
|
26
|
+
: Key extends keyof Type
|
|
27
|
+
? Type[Key] extends Map<string, infer MapType>
|
|
28
|
+
? MapType
|
|
29
|
+
: PropertyType<Type[Key], Rest>
|
|
30
|
+
: unknown
|
|
31
|
+
: unknown;
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
export type MangoQueryRegexOptions = 'i' | 'g' | 'm' | 'gi' | 'ig' | 'igm' | string;
|
|
35
|
+
|
|
36
|
+
/*
|
|
37
|
+
* The MongoDB query library is huge and we do not need all the operators.
|
|
38
|
+
* If you add an operator here, make sure that you properly add a test in
|
|
39
|
+
* the file /test/unit/rx-storage-query-correctness.test.ts
|
|
40
|
+
*
|
|
41
|
+
* @link https://github.com/kofrasa/mingo#es6
|
|
42
|
+
*/
|
|
43
|
+
export interface MangoQueryOperators<PathValueType> {
|
|
44
|
+
$eq?: PathValueType;
|
|
45
|
+
$gt?: PathValueType;
|
|
46
|
+
$gte?: PathValueType;
|
|
47
|
+
$lt?: PathValueType;
|
|
48
|
+
$lte?: PathValueType;
|
|
49
|
+
$ne?: PathValueType;
|
|
50
|
+
$in?: PathValueType[];
|
|
51
|
+
$nin?: PathValueType[];
|
|
52
|
+
$regex?: string;
|
|
53
|
+
$options?: MangoQueryRegexOptions;
|
|
54
|
+
$exists?: boolean;
|
|
55
|
+
$type?: 'null' | 'boolean' | 'number' | 'string' | 'array' | 'object';
|
|
56
|
+
$mod?: [number, number];
|
|
57
|
+
$not?: PathValueType;
|
|
58
|
+
$size?: number;
|
|
59
|
+
$elemMatch?: MangoQuerySelector<PathValueType>;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export type MangoQuerySelector<DocType> = Partial<{
|
|
63
|
+
[Property in Paths<DocType>]: MangoQueryOperators<any> | PropertyType<DocType, Property>;
|
|
64
|
+
}> & {
|
|
65
|
+
$and?: MangoQuerySelector<DocType>[];
|
|
66
|
+
$or?: MangoQuerySelector<DocType>[];
|
|
67
|
+
$nor?: MangoQuerySelector<DocType>[];
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Discussion was at:
|
|
72
|
+
* @link https://github.com/pubkey/rxdb/issues/1972
|
|
73
|
+
*/
|
|
74
|
+
export type MangoQuerySortDirection = 'asc' | 'desc';
|
|
75
|
+
export type MangoQuerySortPart<RxDocType = any> = {
|
|
76
|
+
[k in StringKeys<RxDocType> | string]: MangoQuerySortDirection;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export type MangoQuerySelectorAndIndex<RxDocType = any> = {
|
|
80
|
+
/**
|
|
81
|
+
* Selector is optional,
|
|
82
|
+
* if not given, the query matches all documents
|
|
83
|
+
* that are not _deleted=true.
|
|
84
|
+
*/
|
|
85
|
+
selector?: MangoQuerySelector<RxDocType>;
|
|
86
|
+
/**
|
|
87
|
+
* By default, the RxStorage implementation
|
|
88
|
+
* decides which index to use when running the query.
|
|
89
|
+
*
|
|
90
|
+
* For better performance, a different index might be defined
|
|
91
|
+
* by setting it in the query.
|
|
92
|
+
* How this improves performance and if the defined index is used,
|
|
93
|
+
* depends on the RxStorage implementation.
|
|
94
|
+
*/
|
|
95
|
+
index?: string | string[];
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
export type MangoQueryNoLimit<RxDocType> = MangoQuerySelectorAndIndex<RxDocType> & {
|
|
99
|
+
/**
|
|
100
|
+
* Sorting of the results.
|
|
101
|
+
* If no sort is set, RxDB will sort by the primary key.
|
|
102
|
+
* Also if sort is set, RxDB will add primaryKey sorting
|
|
103
|
+
* if the primaryKey was not in the sort parameters before.
|
|
104
|
+
* This ensures that there is a deterministic sorting of the
|
|
105
|
+
* results, not mather at which order the documents have been
|
|
106
|
+
* inserted into the storage.
|
|
107
|
+
*/
|
|
108
|
+
sort?: MangoQuerySortPart<RxDocType>[];
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
export type MangoQuery<RxDocType = any> = MangoQueryNoLimit<RxDocType> & {
|
|
112
|
+
skip?: number;
|
|
113
|
+
limit?: number;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
export type RxQueryOP = 'find' | 'findOne' | 'count' | 'findByIds';
|
|
117
|
+
|
|
118
|
+
export declare class RxQuery<
|
|
119
|
+
RxDocumentType = any,
|
|
120
|
+
RxQueryResult = any,
|
|
121
|
+
OrmMethods = {},
|
|
122
|
+
Reactivity = unknown
|
|
123
|
+
> extends RxQueryBase<RxDocumentType, RxQueryResult, OrmMethods, Reactivity> {
|
|
124
|
+
equals(queryObj: any): RxQuery<RxDocumentType, RxQueryResult>;
|
|
125
|
+
eq(queryObj: any): RxQuery<RxDocumentType, RxQueryResult>;
|
|
126
|
+
or(queryObj: keyof RxDocumentType | string | any[]): RxQuery<RxDocumentType, RxQueryResult>;
|
|
127
|
+
nor(queryObj: keyof RxDocumentType | string | any[]): RxQuery<RxDocumentType, RxQueryResult>;
|
|
128
|
+
and(queryObj: keyof RxDocumentType | string | any[]): RxQuery<RxDocumentType, RxQueryResult>;
|
|
129
|
+
gt(queryObj: any): RxQuery<RxDocumentType, RxQueryResult>;
|
|
130
|
+
gte(queryObj: any): RxQuery<RxDocumentType, RxQueryResult>;
|
|
131
|
+
lt(queryObj: any): RxQuery<RxDocumentType, RxQueryResult>;
|
|
132
|
+
lte(queryObj: any): RxQuery<RxDocumentType, RxQueryResult>;
|
|
133
|
+
ne(queryObj: any): RxQuery<RxDocumentType, RxQueryResult>;
|
|
134
|
+
in(queryObj: any[]): RxQuery<RxDocumentType, RxQueryResult>;
|
|
135
|
+
nin(queryObj: any[]): RxQuery<RxDocumentType, RxQueryResult>;
|
|
136
|
+
all(queryObj: any): RxQuery<RxDocumentType, RxQueryResult>;
|
|
137
|
+
regex(queryObj: string | {
|
|
138
|
+
$regex: string;
|
|
139
|
+
$options: MangoQueryRegexOptions;
|
|
140
|
+
}): RxQuery<RxDocumentType, RxQueryResult>;
|
|
141
|
+
exists(queryObj: any): RxQuery<RxDocumentType, RxQueryResult>;
|
|
142
|
+
elemMatch(queryObj: any): RxQuery<RxDocumentType, RxQueryResult>;
|
|
143
|
+
mod(p1: any, p2: any, p3: any): RxQuery<RxDocumentType, RxQueryResult>;
|
|
144
|
+
}
|