@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.
Files changed (45) hide show
  1. package/dist/cjs/plugins/storage-dexie/rx-storage-instance-dexie.js +10 -10
  2. package/dist/cjs/plugins/storage-dexie/rx-storage-instance-dexie.js.map +1 -1
  3. package/dist/cjs/plugins/utils/utils-premium.js +4 -4
  4. package/dist/cjs/plugins/utils/utils-premium.js.map +1 -1
  5. package/dist/esm/package.json +1 -0
  6. package/dist/esm/plugins/storage-dexie/rx-storage-instance-dexie.js +10 -10
  7. package/dist/esm/plugins/storage-dexie/rx-storage-instance-dexie.js.map +1 -1
  8. package/dist/esm/plugins/utils/utils-premium.js +4 -4
  9. package/dist/esm/plugins/utils/utils-premium.js.map +1 -1
  10. package/dist/types/index.d.ts +26 -25
  11. package/dist/types/types/conflict-handling.d.ts +48 -0
  12. package/dist/types/types/couchdb.d.ts +293 -0
  13. package/dist/types/types/index.d.ts +32 -0
  14. package/dist/types/types/modules/index.d.ts +0 -0
  15. package/dist/types/types/modules/mocha.parallel.d.ts +1 -0
  16. package/dist/types/types/plugins/backup.d.ts +35 -0
  17. package/dist/types/types/plugins/cleanup.d.ts +38 -0
  18. package/dist/types/types/plugins/crdt.d.ts +76 -0
  19. package/dist/types/types/plugins/dexie.d.ts +30 -0
  20. package/dist/types/types/plugins/local-documents.d.ts +49 -0
  21. package/dist/types/types/plugins/migration.d.ts +14 -0
  22. package/dist/types/types/plugins/reactivity.d.ts +40 -0
  23. package/dist/types/types/plugins/replication-graphql.d.ts +98 -0
  24. package/dist/types/types/plugins/replication.d.ts +175 -0
  25. package/dist/types/types/plugins/state.d.ts +4 -0
  26. package/dist/types/types/plugins/update.d.ts +23 -0
  27. package/dist/types/types/plugins/webmcp.d.ts +40 -0
  28. package/dist/types/types/query-planner.d.ts +47 -0
  29. package/dist/types/types/replication-protocol.d.ts +296 -0
  30. package/dist/types/types/rx-attachment.d.ts +46 -0
  31. package/dist/types/types/rx-change-event.d.ts +85 -0
  32. package/dist/types/types/rx-collection.d.ts +117 -0
  33. package/dist/types/types/rx-database-internal-store.d.ts +54 -0
  34. package/dist/types/types/rx-database.d.ts +124 -0
  35. package/dist/types/types/rx-document.d.ts +160 -0
  36. package/dist/types/types/rx-error.d.ts +225 -0
  37. package/dist/types/types/rx-plugin.d.ts +167 -0
  38. package/dist/types/types/rx-query.d.ts +144 -0
  39. package/dist/types/types/rx-schema.d.ts +214 -0
  40. package/dist/types/types/rx-storage.d.ts +347 -0
  41. package/dist/types/types/rx-storage.interface.d.ts +312 -0
  42. package/dist/types/types/util.d.ts +180 -0
  43. package/package.json +732 -732
  44. package/scripts/copy-path.mjs +20 -0
  45. package/scripts/fix-types.mjs +15 -8
@@ -0,0 +1,312 @@
1
+ import type {
2
+ BulkWriteRow,
3
+ EventBulk,
4
+ RxDocumentData,
5
+ RxStorageBulkWriteResponse,
6
+ RxStorageChangeEvent,
7
+ RxStorageCountResult,
8
+ RxStorageInstanceCreationParams,
9
+ RxStorageQueryResult
10
+ } from './rx-storage.ts';
11
+ import type {
12
+ MangoQuerySelector,
13
+ MangoQuerySortPart,
14
+ RxJsonSchema,
15
+ RxQueryPlan
16
+ } from './index.d.ts';
17
+ import type {
18
+ Observable
19
+ } from 'rxjs';
20
+
21
+ /**
22
+ * RxStorage
23
+ * This is an interface that abstracts the storage engine.
24
+ * This allows us to use RxDB with different storage engines.
25
+ *
26
+ * @link https://rxdb.info/rx-storage.html
27
+ * @link https://github.com/pubkey/rxdb/issues/1636
28
+ */
29
+
30
+ /**
31
+ * A RxStorage is a module that acts
32
+ * as a factory that can create multiple RxStorageInstance
33
+ * objects.
34
+ *
35
+ * All data inputs and outputs of a StorageInstance must be structured-cloneable.
36
+ * Document data must be plain JSON objects. Attachment data uses Blob.
37
+ * Do not use Map, Set or anything else that is not structured-cloneable.
38
+ * This will ensure that the storage can exchange data
39
+ * when it is a WebWorker or a WASM process or data is send via BroadcastChannel.
40
+ * The only exception is the WebSocket transport, which serializes at its boundary.
41
+ */
42
+ export interface RxStorage<Internals, InstanceCreationOptions> {
43
+ /**
44
+ * name of the storage engine
45
+ * used to detect if plugins do not work so we can throw proper errors.
46
+ */
47
+ readonly name: string;
48
+
49
+ /**
50
+ * RxDB version is part of the storage
51
+ * so we can have fallbacks and stuff when
52
+ * multiple storages with different version are in use
53
+ * like in the storage migration plugin.
54
+ */
55
+ readonly rxdbVersion: string;
56
+
57
+ /**
58
+ * Creates a storage instance
59
+ * that can contain the NoSQL documents of a collection.
60
+ */
61
+ createStorageInstance<RxDocType>(
62
+ params: RxStorageInstanceCreationParams<RxDocType, InstanceCreationOptions>
63
+ ): Promise<RxStorageInstance<RxDocType, Internals, InstanceCreationOptions>>;
64
+ }
65
+
66
+
67
+ /**
68
+ * User provided mango queries will be filled up by RxDB via normalizeMangoQuery()
69
+ * so we do not have to do many if-field-exist tests in the internals.
70
+ */
71
+ export type FilledMangoQuery<RxDocType> = {
72
+ /**
73
+ * The selector is required here.
74
+ */
75
+ selector: MangoQuerySelector<RxDocumentData<RxDocType>>;
76
+
77
+ /**
78
+ * In contrast to the user-provided MangoQuery,
79
+ * the sorting is required here because
80
+ * RxDB has to ensure that the primary key is always
81
+ * part of the sort params.
82
+ */
83
+ sort: MangoQuerySortPart<RxDocumentData<RxDocType>>[];
84
+
85
+ /**
86
+ * In the normalized mango query,
87
+ * the index must always be a string[],
88
+ * never just a string.
89
+ * This makes it easier to use the query because
90
+ * we do not have to do an array check.
91
+ */
92
+ index?: string[];
93
+
94
+ /**
95
+ * Skip must be set which defaults to 0
96
+ */
97
+ skip: number;
98
+
99
+ limit?: number;
100
+ };
101
+
102
+
103
+ /**
104
+ * Before sending a query to the storageInstance.query()
105
+ * we run it through the query planner and do some normalization
106
+ * stuff. Notice that the queryPlan is a hint for the storage and
107
+ * it is not required to use it when running queries. Some storages
108
+ * might use their own query planning instead.
109
+ */
110
+ export type PreparedQuery<RxDocType> = {
111
+ // original query from the input
112
+ query: FilledMangoQuery<RxDocType>;
113
+ queryPlan: RxQueryPlan;
114
+ };
115
+
116
+ export interface RxStorageInstance<
117
+ /**
118
+ * The type of the documents that can be stored in this instance.
119
+ * All documents in an instance must comply to the same schema.
120
+ * Also all documents are RxDocumentData with the meta properties like
121
+ * _deleted or _rev etc.
122
+ */
123
+ RxDocType,
124
+ Internals,
125
+ InstanceCreationOptions,
126
+ CheckpointType = any
127
+ > {
128
+ readonly databaseName: string;
129
+ /**
130
+ * Returns the internal data that is used by the storage engine.
131
+ */
132
+ readonly internals: Readonly<Internals>;
133
+ readonly options: Readonly<InstanceCreationOptions>;
134
+ /**
135
+ * The schema that defines the documents that are stored in this instance.
136
+ * Notice that the schema must be enhanced with the meta properties like
137
+ * _meta, _rev and _deleted etc. which are added by fillWithDefaultSettings()
138
+ */
139
+ readonly schema: Readonly<RxJsonSchema<RxDocumentData<RxDocType>>>;
140
+ readonly collectionName: string;
141
+
142
+ /**
143
+ * (Optional) reference to the underlying persistent storage instance.
144
+ * If set, things like replication will run on that storageInstance instead of the parent.
145
+ * This is mostly used in things like the memory-synced storage where we want to
146
+ * run replications and migrations on the persistent storage instead of the in-memory storage.
147
+ *
148
+ * Having this is the least hacky option. The only other option would be to toggle all calls to the
149
+ * storageInstance by checking the givent context-string. But this would make it impossible
150
+ * to run a replication on the parentStorage itself.
151
+ */
152
+ readonly underlyingPersistentStorage?: RxStorageInstance<RxDocType, any, any, any>;
153
+
154
+ /**
155
+ * Writes multiple documents to the storage instance.
156
+ * The write for each single document is atomic, there
157
+ * is no transaction around all documents.
158
+ * The written documents must be the newest revision of that documents data.
159
+ * If the previous document is not the current newest revision, a conflict error
160
+ * must be returned.
161
+ * It must be possible that some document writes succeed
162
+ * and others error. We need this to have a similar behavior as most NoSQL databases.
163
+ */
164
+ bulkWrite(
165
+ documentWrites: BulkWriteRow<RxDocType>[],
166
+ /**
167
+ * Context will be used in all
168
+ * changeStream()-events that are emitted as a result
169
+ * of that bulkWrite() operation.
170
+ * Used in plugins so that we can detect that event X
171
+ * comes from operation Y.
172
+ */
173
+ context: string
174
+ ): Promise<RxStorageBulkWriteResponse<RxDocType>>;
175
+
176
+ /**
177
+ * Get Multiple documents by their primary value.
178
+ * This must also return deleted documents.
179
+ */
180
+ findDocumentsById(
181
+ /**
182
+ * List of primary values
183
+ * of the documents to find.
184
+ */
185
+ ids: string[],
186
+ /**
187
+ * If set to true, deleted documents will also be returned.
188
+ */
189
+ withDeleted: boolean
190
+
191
+ ): Promise<
192
+ /**
193
+ * For better performance, we return an array
194
+ * instead of an indexed object because most consumers
195
+ * of this anyway have to fill a Map() instance or
196
+ * even do only need the list at all.
197
+ */
198
+ RxDocumentData<RxDocType>[]
199
+ >;
200
+
201
+ /**
202
+ * Runs a NoSQL 'mango' query over the storage
203
+ * and returns the found documents data.
204
+ * Having all storage instances behave similar
205
+ * is likely the most difficult thing when creating a new
206
+ * rx-storage implementation.
207
+ */
208
+ query(
209
+ preparedQuery: PreparedQuery<RxDocType>
210
+ ): Promise<RxStorageQueryResult<RxDocType>>;
211
+
212
+ /**
213
+ * Returns the amount of non-deleted documents
214
+ * that match the given query.
215
+ * Sort, skip and limit of the query must be ignored!
216
+ */
217
+ count(
218
+ preparedQuery: PreparedQuery<RxDocType>
219
+ ): Promise<RxStorageCountResult>;
220
+
221
+ /**
222
+ * Returns the data of a single attachment as a Blob.
223
+ */
224
+ getAttachmentData(
225
+ documentId: string,
226
+ attachmentId: string,
227
+ digest: string
228
+ ): Promise<Blob>;
229
+
230
+ /**
231
+ * Returns the current (not the old!) data of all documents that have been changed AFTER the given checkpoint.
232
+ * If the returned array does not reach the limit, it can be assumed that the "end" is reached, when paginating over the changes.
233
+ * Also returns a new checkpoint for each document which can be used to continue with the pagination from that change on.
234
+ * Must never return the same document multiple times in the same call operation.
235
+ * This is used by RxDB to known what has changed since X so these docs can be handled by the backup or the replication
236
+ * plugin.
237
+ *
238
+ * Important: This method is optional. If not defined,
239
+ * RxDB will manually run a query and use the last returned document
240
+ * for checkpointing. In the future we might even remove this method completely
241
+ * and let RxDB do the work instead of the RxStorage.
242
+ */
243
+ getChangedDocumentsSince?(
244
+ limit: number,
245
+ /**
246
+ * The checkpoint from with to start
247
+ * when the events are sorted in time.
248
+ * If we want to start from the beginning,
249
+ * undefined is used as a checkpoint.
250
+ */
251
+ checkpoint?: CheckpointType
252
+ ): Promise<{
253
+ documents: RxDocumentData<RxDocType>[];
254
+ /**
255
+ * The checkpoint contains data so that another
256
+ * call to getChangedDocumentsSince() will continue
257
+ * from exactly the last document that was returned before.
258
+ */
259
+ checkpoint: CheckpointType;
260
+ }>;
261
+
262
+ /**
263
+ * Returns an ongoing stream
264
+ * of all changes that happen to the
265
+ * storage instance.
266
+ * Do not forget to unsubscribe.
267
+ *
268
+ * If the RxStorage support multi-instance,
269
+ * and the storage is persistent,
270
+ * then the emitted changes of one RxStorageInstance
271
+ * must be also emitted to other instances with the same databaseName+collectionName.
272
+ * See ./rx-storage-multiinstance.ts
273
+ */
274
+ changeStream(): Observable<EventBulk<RxStorageChangeEvent<RxDocType>, CheckpointType>>;
275
+
276
+ /**
277
+ * Runs a cleanup that removes all tompstones
278
+ * of documents that have _deleted set to true
279
+ * to free up disc space.
280
+ *
281
+ * Returns true if all cleanable documents have been removed.
282
+ * Returns false if there are more documents to be cleaned up,
283
+ * but not all have been purged because that would block the storage for too long.
284
+ */
285
+ cleanup(
286
+ /**
287
+ * The minimum time in milliseconds
288
+ * of how long a document must have been deleted
289
+ * until it is purged by the cleanup.
290
+ */
291
+ minimumDeletedTime: number
292
+ ): Promise<
293
+ /**
294
+ * True if all docs cleaned up,
295
+ * false if there are more docs to clean up
296
+ */
297
+ boolean
298
+ >;
299
+
300
+ /**
301
+ * Closes the storage instance so it cannot be used
302
+ * anymore and should clear all memory.
303
+ * The returned promise must resolve when everything is cleaned up.
304
+ */
305
+ close(): Promise<void>;
306
+
307
+ /**
308
+ * Remove the database and
309
+ * deletes all of its data.
310
+ */
311
+ remove(): Promise<void>;
312
+ }
@@ -0,0 +1,180 @@
1
+ import type { RxStorage } from './rx-storage.interface';
2
+
3
+ export type MaybePromise<T> = Promise<T> | T;
4
+
5
+
6
+ export type PlainJsonValue =
7
+ string |
8
+ number |
9
+ boolean |
10
+ PlainSimpleJsonObject |
11
+ PlainSimpleJsonObject[] |
12
+ PlainJsonValue[] |
13
+ { [key: string]: PlainJsonValue; }
14
+ ;
15
+ export type PlainSimpleJsonObject = {
16
+ [k: string]: PlainJsonValue | PlainJsonValue[];
17
+ };
18
+
19
+ /**
20
+ * @link https://stackoverflow.com/a/49670389/3443137
21
+ */
22
+ type DeepReadonly<T> =
23
+ T extends (infer R)[] ? DeepReadonlyArray<R> :
24
+ T extends Function ? T :
25
+ T extends object ? DeepReadonlyObject<T> :
26
+ T;
27
+
28
+ interface DeepReadonlyArray<T> extends ReadonlyArray<DeepReadonly<T>> { }
29
+
30
+ type DeepReadonlyObject<T> = {
31
+ readonly [P in keyof T]: DeepReadonly<T[P]>;
32
+ };
33
+
34
+ export type MaybeReadonly<T> = T | Readonly<T>;
35
+
36
+
37
+ /**
38
+ * Opposite of DeepReadonly,
39
+ * makes everything mutable again.
40
+ */
41
+ type DeepMutable<T> = (
42
+ T extends object
43
+ ? {
44
+ -readonly [K in keyof T]: (
45
+ T[K] extends object
46
+ ? DeepMutable<T[K]>
47
+ : T[K]
48
+ )
49
+ }
50
+ : never
51
+ );
52
+
53
+ /**
54
+ * Can be used like 'keyof'
55
+ * but only represents the string keys, not the Symbols or numbers.
56
+ * @link https://stackoverflow.com/a/51808262/3443137
57
+ */
58
+ export type StringKeys<X> = Extract<keyof X, string>;
59
+
60
+ export type AnyKeys<T> = { [P in keyof T]?: T[P] | any };
61
+ export interface AnyObject {
62
+ [k: string]: any;
63
+ }
64
+
65
+ /**
66
+ * @link https://dev.to/vborodulin/ts-how-to-override-properties-with-type-intersection-554l
67
+ */
68
+ export type Override<T1, T2> = Omit<T1, keyof T2> & T2;
69
+
70
+
71
+
72
+ export type ById<T> = {
73
+ [id: string]: T;
74
+ };
75
+
76
+ /**
77
+ * Must be async to support async hashing like from the WebCrypto API.
78
+ * Accepts string for document revision hashing,
79
+ * ArrayBuffer for raw binary hashing,
80
+ * or Blob for attachment digest hashing.
81
+ */
82
+ export type HashFunction = (input: string | ArrayBuffer | Blob) => Promise<string>;
83
+
84
+ export declare type QueryMatcher<DocType> = (doc: DocType | DeepReadonly<DocType>) => boolean;
85
+
86
+ /**
87
+ * To have a deterministic sorting, we cannot return 0,
88
+ * we only return 1 or -1.
89
+ * This ensures that we always end with the same output array, no mather of the
90
+ * pre-sorting of the input array.
91
+ */
92
+ export declare type DeterministicSortComparator<DocType> = (a: DocType, b: DocType) => 1 | -1;
93
+
94
+ /**
95
+ * To test a storage, we need these
96
+ * configuration values.
97
+ */
98
+ export type RxTestStorage = {
99
+ // can be used to setup async stuff
100
+ readonly init?: () => any;
101
+ readonly name: string;
102
+ readonly getStorage: () => RxStorage<any, any>;
103
+ /**
104
+ * Returns a storage that is used in performance tests.
105
+ * For example in a browser it should return the storage with an IndexedDB based adapter,
106
+ * while in node.js it must use the filesystem.
107
+ */
108
+ readonly getPerformanceStorage: () => {
109
+ storage: RxStorage<any, any>;
110
+ /**
111
+ * A description that describes the storage and setting.
112
+ * For example 'dexie-native'.
113
+ */
114
+ description: string;
115
+ };
116
+ /**
117
+ * True if the storage is able to
118
+ * keep data after an instance is closed and opened again.
119
+ */
120
+ readonly hasPersistence: boolean;
121
+ readonly hasMultiInstance: boolean;
122
+ readonly hasAttachments: boolean;
123
+
124
+ /**
125
+ * Some storages likes the memory-synced storage,
126
+ * are not able to provide a replication while guaranteeing
127
+ * data integrity.
128
+ */
129
+ readonly hasReplication: boolean;
130
+
131
+ /**
132
+ * To make it possible to test alternative encryption plugins,
133
+ * you can specify hasEncryption to signal
134
+ * the test runner that the given storage already contains an
135
+ * encryption plugin that should be used to test encryption tests.
136
+ * Otherwise the encryption-crypto-js plugin will be tested.
137
+ *
138
+ * hasEncryption must contain a function that is able
139
+ * to create a new password.
140
+ */
141
+ readonly hasEncryption?: () => Promise<string>;
142
+ };
143
+
144
+
145
+ /**
146
+ * The paths as strings-type of nested object
147
+ * @link https://stackoverflow.com/a/58436959/3443137
148
+ */
149
+ type Join<K, P> = K extends string | number ?
150
+ P extends string | number ?
151
+ `${K}${'' extends P ? '' : '.'}${P}`
152
+ : never : never;
153
+
154
+ export type Paths<T, D extends number = 10> = [D] extends [never] ? never : T extends object ?
155
+ { [K in keyof T]-?: K extends string | number ?
156
+ `${K}` | (Paths<T[K], Prev[D]> extends infer R ? Join<K, R> : never)
157
+ : never
158
+ }[keyof T] : '';
159
+
160
+ export type Leaves<T, D extends number = 10> = [D] extends [never] ? never : T extends object ?
161
+ { [K in keyof T]-?: Join<K, Leaves<T[K], Prev[D]>> }[keyof T] : '';
162
+ type Prev = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
163
+ 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...0[]];
164
+
165
+
166
+
167
+ /**
168
+ * In the past, users had to add WeakRef to their typescript config.
169
+ * To create an easier setup, we use our own typings instead, because WeakRef
170
+ * is used internally only anyways.
171
+ */
172
+
173
+ export interface WeakRef<T extends object = any> {
174
+ deref(): T | undefined;
175
+ }
176
+
177
+ export interface FinalizationRegistry<T> {
178
+ register(target: object, heldValue: T, unregisterToken?: object): void;
179
+ unregister(unregisterToken: object): boolean;
180
+ }