@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,214 @@
|
|
|
1
|
+
import { AsTyped } from 'as-typed';
|
|
2
|
+
import type { CRDTSchemaOptions } from './plugins/crdt.d.ts';
|
|
3
|
+
import type { StringKeys } from './util.d.ts';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @link https://github.com/types/lib-json-schema/blob/master/v4/index.d.ts
|
|
7
|
+
*/
|
|
8
|
+
export type JsonSchemaTypes = 'array' | 'boolean' | 'integer' | 'number' | 'null' | 'object' | 'string' | (string & {});
|
|
9
|
+
|
|
10
|
+
export type CompositePrimaryKey<RxDocType> = {
|
|
11
|
+
/**
|
|
12
|
+
* The top level field of the document that will be used
|
|
13
|
+
* to store the composite key as string.
|
|
14
|
+
*/
|
|
15
|
+
key: StringKeys<RxDocType>;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The fields of the composite key,
|
|
19
|
+
* the fields must be required and final
|
|
20
|
+
* and have the type number, int, or string.
|
|
21
|
+
*/
|
|
22
|
+
fields: (StringKeys<RxDocType> | string)[] | readonly (StringKeys<RxDocType> | string)[];
|
|
23
|
+
/**
|
|
24
|
+
* The separator which is used to concat the
|
|
25
|
+
* primary fields values.
|
|
26
|
+
* Choose a character as separator that is known
|
|
27
|
+
* to never appear inside of the primary fields values.
|
|
28
|
+
* I recommend to use the pipe char '|'.
|
|
29
|
+
*/
|
|
30
|
+
separator: string;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export type PrimaryKey<RxDocType> = StringKeys<RxDocType> | CompositePrimaryKey<RxDocType>;
|
|
34
|
+
|
|
35
|
+
export type JsonSchema<RxDocType = any> = {
|
|
36
|
+
allOf?: JsonSchema[] | readonly JsonSchema[];
|
|
37
|
+
anyOf?: JsonSchema[] | readonly JsonSchema[];
|
|
38
|
+
oneOf?: JsonSchema[] | readonly JsonSchema[];
|
|
39
|
+
additionalItems?: boolean | JsonSchema;
|
|
40
|
+
additionalProperties?: boolean | JsonSchema;
|
|
41
|
+
type?: JsonSchemaTypes | JsonSchemaTypes[] | readonly JsonSchemaTypes[];
|
|
42
|
+
description?: string;
|
|
43
|
+
dependencies?: {
|
|
44
|
+
[key: string]: JsonSchema | string[] | readonly string[];
|
|
45
|
+
};
|
|
46
|
+
exclusiveMinimum?: number;
|
|
47
|
+
exclusiveMaximum?: number;
|
|
48
|
+
items?: JsonSchema | JsonSchema[] | readonly JsonSchema[];
|
|
49
|
+
multipleOf?: number;
|
|
50
|
+
maxProperties?: number;
|
|
51
|
+
maximum?: number;
|
|
52
|
+
minimum?: number;
|
|
53
|
+
/**
|
|
54
|
+
* Having a large maxLength for indexed fields and primary keys can negatively
|
|
55
|
+
* impact performance on many storages. Therefore, you should only set it
|
|
56
|
+
* as big as needed.
|
|
57
|
+
*/
|
|
58
|
+
maxLength?: number;
|
|
59
|
+
minLength?: number;
|
|
60
|
+
maxItems?: number;
|
|
61
|
+
minItems?: number;
|
|
62
|
+
minProperties?: number;
|
|
63
|
+
pattern?: string;
|
|
64
|
+
patternProperties?: {
|
|
65
|
+
[key: string]: JsonSchema;
|
|
66
|
+
};
|
|
67
|
+
properties?: {
|
|
68
|
+
[key in StringKeys<RxDocType>]: JsonSchema;
|
|
69
|
+
};
|
|
70
|
+
required?: string[] | readonly string[];
|
|
71
|
+
uniqueItems?: boolean;
|
|
72
|
+
enum?: any[] | readonly any[];
|
|
73
|
+
not?: JsonSchema;
|
|
74
|
+
definitions?: {
|
|
75
|
+
[key: string]: JsonSchema;
|
|
76
|
+
};
|
|
77
|
+
format?: 'date-time' | 'email' | 'hostname' | 'ipv4' | 'ipv6' | 'uri' | string;
|
|
78
|
+
example?: any;
|
|
79
|
+
|
|
80
|
+
// RxDB-specific
|
|
81
|
+
ref?: string;
|
|
82
|
+
final?: boolean;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export interface TopLevelProperty extends JsonSchema {
|
|
86
|
+
default?: any;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* @link https://developer.mozilla.org/en-US/docs/Web/API/Compression_Streams_API
|
|
91
|
+
*/
|
|
92
|
+
export type CompressionMode = 'deflate' | 'gzip';
|
|
93
|
+
|
|
94
|
+
export type RxJsonSchema<
|
|
95
|
+
/**
|
|
96
|
+
* The doctype must be given, and '=any' cannot be used,
|
|
97
|
+
* otherwise the keyof of primaryKey
|
|
98
|
+
* would be optional when the type of the document is not known.
|
|
99
|
+
*/
|
|
100
|
+
RxDocType
|
|
101
|
+
> = {
|
|
102
|
+
title?: string;
|
|
103
|
+
description?: string;
|
|
104
|
+
version: number;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* The primary key of the documents.
|
|
108
|
+
* Must be in the top level of the properties of the schema
|
|
109
|
+
* and that property must have the type 'string'
|
|
110
|
+
*/
|
|
111
|
+
primaryKey: PrimaryKey<RxDocType>;
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* TODO this looks like a typescript-bug
|
|
115
|
+
* we have to allows all string because the 'object'-literal is not recognized
|
|
116
|
+
* retry this in later typescript-versions
|
|
117
|
+
*/
|
|
118
|
+
type: 'object' | string;
|
|
119
|
+
|
|
120
|
+
properties: { [key in StringKeys<RxDocType>]: TopLevelProperty };
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* On the top level the required-array must be set
|
|
124
|
+
* because we always have to set the primary key to required.
|
|
125
|
+
*/
|
|
126
|
+
required?: StringKeys<RxDocType>[] | readonly StringKeys<RxDocType>[];
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Indexes that will be used for the queries.
|
|
130
|
+
* RxDB will internally prepend the _deleted field to the index
|
|
131
|
+
* because queries do NOT return documents with _deleted=true.
|
|
132
|
+
* @example ['firstName', ['lastName', 'yearOfBirth']]
|
|
133
|
+
*/
|
|
134
|
+
indexes?: (string | string[])[] | (string | readonly string[])[] | readonly (string | string[])[] | readonly (string | readonly string[])[];
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Internally used indexes that do not get _deleted prepended
|
|
138
|
+
* by RxDB. Use these to speed up queries that are run manually on the storage
|
|
139
|
+
* or to speed up requests when you use the RxDB server.
|
|
140
|
+
* These could also be utilised when you build a plugin that
|
|
141
|
+
* has to query documents without respecting the _deleted value.
|
|
142
|
+
* @example [['firstName'], ['lastName', 'yearOfBirth']]
|
|
143
|
+
*/
|
|
144
|
+
internalIndexes?: string[][] | readonly string[][];
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Array of fields that should be encrypted.
|
|
149
|
+
* @link https://rxdb.info/encryption.html
|
|
150
|
+
* @example ['secret']
|
|
151
|
+
*/
|
|
152
|
+
encrypted?: string[] | readonly string[];
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Enables key compression for the collection to reduce storage size.
|
|
156
|
+
* @link https://rxdb.info/key-compression.html
|
|
157
|
+
* @example true
|
|
158
|
+
*/
|
|
159
|
+
keyCompression?: boolean;
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* if not set, rxdb will set 'false' as default
|
|
163
|
+
* Having additionalProperties: true is not allowed on the root level to ensure
|
|
164
|
+
* that property names do not clash with properties of the RxDocument class
|
|
165
|
+
* or ORM methods.
|
|
166
|
+
*/
|
|
167
|
+
additionalProperties?: false;
|
|
168
|
+
attachments?: {
|
|
169
|
+
encrypted?: boolean;
|
|
170
|
+
/**
|
|
171
|
+
* @link https://developer.mozilla.org/en-US/docs/Web/API/Compression_Streams_API
|
|
172
|
+
*/
|
|
173
|
+
compression?: CompressionMode;
|
|
174
|
+
/**
|
|
175
|
+
* Optional whitelist of MIME type patterns that should be compressed.
|
|
176
|
+
* Supports '*' suffix for prefix matching (e.g., 'text/*').
|
|
177
|
+
* If omitted, a built-in default list of compressible types is used.
|
|
178
|
+
* Only relevant when 'compression' is set.
|
|
179
|
+
*/
|
|
180
|
+
compressibleTypes?: string[];
|
|
181
|
+
};
|
|
182
|
+
/**
|
|
183
|
+
* Options for the sharding plugin of rxdb-premium.
|
|
184
|
+
* We set these on the schema because changing the shard amount or mode
|
|
185
|
+
* will require a migration.
|
|
186
|
+
* @link https://rxdb.info/rx-storage-sharding.html
|
|
187
|
+
*/
|
|
188
|
+
sharding?: {
|
|
189
|
+
/**
|
|
190
|
+
* Amount of shards.
|
|
191
|
+
* This value cannot be changed after you have stored data,
|
|
192
|
+
* if you change it anyway, you will loose the existing data.
|
|
193
|
+
*/
|
|
194
|
+
shards: number;
|
|
195
|
+
/**
|
|
196
|
+
* Either shard by collection or by database.
|
|
197
|
+
* For most use cases (IndexedDB based storages), sharding by collection is the way to go
|
|
198
|
+
* because it has a faster initial load time.
|
|
199
|
+
*/
|
|
200
|
+
mode: 'database' | 'collection';
|
|
201
|
+
};
|
|
202
|
+
/**
|
|
203
|
+
* Configuration for Conflict-free Replicated Data Types (CRDTs).
|
|
204
|
+
* @link https://rxdb.info/crdt.html
|
|
205
|
+
* @example { field: 'crdts' }
|
|
206
|
+
*/
|
|
207
|
+
crdt?: CRDTSchemaOptions<RxDocType>;
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Used to aggregate the document type from the schema.
|
|
212
|
+
* @link https://github.com/pubkey/rxdb/discussions/3467
|
|
213
|
+
*/
|
|
214
|
+
export type ExtractDocumentTypeFromTypedRxJsonSchema<TypedRxJsonSchema> = AsTyped<TypedRxJsonSchema>;
|
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
import type { ChangeEvent } from 'event-reduce-js';
|
|
2
|
+
import type { RxChangeEvent } from './rx-change-event.d.ts';
|
|
3
|
+
import type { RxDocumentMeta } from './rx-document.d.ts';
|
|
4
|
+
import type { RxStorageWriteError } from './rx-error.d.ts';
|
|
5
|
+
import type { RxJsonSchema } from './rx-schema.d.ts';
|
|
6
|
+
import type { Override } from './util.d.ts';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The document data how it comes out of the storage instance.
|
|
10
|
+
* Contains all meta data like revision, attachments and deleted-flag.
|
|
11
|
+
*/
|
|
12
|
+
export type RxDocumentData<T> = T & {
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* As other NoSQL databases,
|
|
16
|
+
* RxDB also assumes that no data is finally deleted.
|
|
17
|
+
* Instead the documents are stored with _deleted: true
|
|
18
|
+
* which means they will not be returned at queries.
|
|
19
|
+
*/
|
|
20
|
+
_deleted: boolean;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The attachments meta data is stored besides to document.
|
|
24
|
+
*/
|
|
25
|
+
_attachments: {
|
|
26
|
+
[attachmentId: string]: RxAttachmentData;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Contains a revision which is concatenated with a [height: number]-[identifier: string]
|
|
31
|
+
* like: '1-3hl4kj3l4kgj34g34glk'.
|
|
32
|
+
* The revision is used to detect write conflicts and have a document history.
|
|
33
|
+
* Revisions behave similar to couchdb revisions:
|
|
34
|
+
* @link https://docs.couchdb.org/en/stable/replication/conflicts.html#revision-tree
|
|
35
|
+
|
|
36
|
+
* When writing a document, you must send the correct revision in the previous-field
|
|
37
|
+
* to make sure that you do not cause a write conflict.
|
|
38
|
+
* The revision of the 'new' document-field must be created, for example via util.createRevision().
|
|
39
|
+
* Any revision that matches the [height]-[hash] format can be used.
|
|
40
|
+
*/
|
|
41
|
+
_rev: string;
|
|
42
|
+
_meta: RxDocumentMeta;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export type RxDocumentDataById<RxDocType> = {
|
|
46
|
+
[documentId: string]: RxDocumentData<RxDocType>;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The document data how it is send to the
|
|
51
|
+
* storage instance to save it.
|
|
52
|
+
*/
|
|
53
|
+
// We & T here instead of in RxDocumentData to preserver indexability by keyof T which the Override breaks
|
|
54
|
+
export type RxDocumentWriteData<T> = T & Override<RxDocumentData<{}>, {
|
|
55
|
+
_attachments: {
|
|
56
|
+
/**
|
|
57
|
+
* To create a new attachment, set the write data
|
|
58
|
+
* To delete an attachment, leave it out on the _attachments property.
|
|
59
|
+
* To change an attachment, set the new write data.
|
|
60
|
+
* To not touch an attachment, just send the stub again
|
|
61
|
+
* which came out of the storage instance.
|
|
62
|
+
*/
|
|
63
|
+
[attachmentId: string]: RxAttachmentData | RxAttachmentWriteData;
|
|
64
|
+
};
|
|
65
|
+
}>;
|
|
66
|
+
|
|
67
|
+
export type WithDeleted<DocType> = DocType & {
|
|
68
|
+
_deleted: boolean;
|
|
69
|
+
};
|
|
70
|
+
export type WithDeletedAndAttachments<DocType> = DocType & {
|
|
71
|
+
_deleted: boolean;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Here the _attachments might exist
|
|
75
|
+
* or might not, depending one the use case.
|
|
76
|
+
*/
|
|
77
|
+
_attachments?: {
|
|
78
|
+
[attachmentId: string]: RxAttachmentData | RxAttachmentWriteData;
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Send to the bulkWrite() method of a storage instance.
|
|
84
|
+
*/
|
|
85
|
+
export type BulkWriteRow<RxDocType> = {
|
|
86
|
+
/**
|
|
87
|
+
* The current document state in the storage engine,
|
|
88
|
+
* assumed by the application.
|
|
89
|
+
* Undefined if the document is a new insert.
|
|
90
|
+
* Notice that we send the full document data as 'previous', not just the revision.
|
|
91
|
+
* The reason is that to get the previous revision you anyway have to get the full
|
|
92
|
+
* previous document and so it is easier to just send it all to the storage instance.
|
|
93
|
+
* This will later allow us to use something different then the _rev key for conflict detection
|
|
94
|
+
* when we implement other storage instances.
|
|
95
|
+
*/
|
|
96
|
+
previous?: RxDocumentData<RxDocType>;
|
|
97
|
+
/**
|
|
98
|
+
* The new document data to be stored in the storage instance.
|
|
99
|
+
*/
|
|
100
|
+
document: RxDocumentWriteData<RxDocType>;
|
|
101
|
+
};
|
|
102
|
+
export type BulkWriteRowById<RxDocType> = {
|
|
103
|
+
[documentId: string]: BulkWriteRow<RxDocType>;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* After the RxStorage has processed all rows,
|
|
108
|
+
* we have this to work with afterwards.
|
|
109
|
+
*/
|
|
110
|
+
export type BulkWriteRowProcessed<RxDocType> = BulkWriteRow<RxDocType> & {
|
|
111
|
+
document: RxDocumentData<RxDocType>;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
export type RxAttachmentData = {
|
|
116
|
+
/**
|
|
117
|
+
* Size of the attachments data
|
|
118
|
+
*/
|
|
119
|
+
length: number;
|
|
120
|
+
/**
|
|
121
|
+
* Content type like 'plain/text'
|
|
122
|
+
*/
|
|
123
|
+
type: string;
|
|
124
|
+
/**
|
|
125
|
+
* The hash of the attachments content.
|
|
126
|
+
* It is calculated by RxDB, and send to the storage.
|
|
127
|
+
* The only guarantee is that the digest will change when the attachments data changes.
|
|
128
|
+
* @link https://github.com/pouchdb/pouchdb/issues/3156#issuecomment-66831010
|
|
129
|
+
* @link https://github.com/pubkey/rxdb/pull/4107
|
|
130
|
+
*/
|
|
131
|
+
digest: string;
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Data which is needed for new attachments
|
|
136
|
+
* that are send from RxDB to the RxStorage implementation.
|
|
137
|
+
*/
|
|
138
|
+
export type RxAttachmentWriteData = RxAttachmentData & {
|
|
139
|
+
/**
|
|
140
|
+
* The data of the attachment as a Blob.
|
|
141
|
+
* Blob is the canonical internal type because:
|
|
142
|
+
* - Attachments are blob-like things (images, videos, PDFs)
|
|
143
|
+
* - Blob is immutable (safe, no accidental mutation)
|
|
144
|
+
* - Blob.type carries MIME type metadata
|
|
145
|
+
* - Blob.size gives length synchronously
|
|
146
|
+
* - Blob is structured-cloneable (works with Worker/Electron postMessage)
|
|
147
|
+
* - IndexedDB stores Blobs efficiently (some engines use external blob storage)
|
|
148
|
+
*
|
|
149
|
+
* Conversion to ArrayBuffer only happens at boundaries that require it:
|
|
150
|
+
* encryption (Web Crypto), compression (CompressionStream), digest hashing,
|
|
151
|
+
* and WebSocket serialization.
|
|
152
|
+
*
|
|
153
|
+
* Encryption/compression run in the wrapRxStorageInstance layer OUTSIDE
|
|
154
|
+
* storage transactions, so Blob does not extend transaction lifetimes.
|
|
155
|
+
*/
|
|
156
|
+
data: Blob;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* The returned data from RxStorageInstance.bulkWrite()
|
|
162
|
+
* For better performance, we do NOT use an indexed object,
|
|
163
|
+
* but only plain arrays. Because most of the time
|
|
164
|
+
* RxDB anyway only need the array data and we can save performance
|
|
165
|
+
* by not indexing the results.
|
|
166
|
+
*
|
|
167
|
+
* We do not longer return the written documents. We only return the errors.
|
|
168
|
+
* This is because we construct the written docs array from the input+errors anyway
|
|
169
|
+
* and transferring large amounts of data has bad performance when the storage
|
|
170
|
+
* is running in a different realm like a WebWorker or remote.
|
|
171
|
+
*/
|
|
172
|
+
export type RxStorageBulkWriteResponse<RxDocType> = {
|
|
173
|
+
/**
|
|
174
|
+
* contains all errored writes.
|
|
175
|
+
*/
|
|
176
|
+
error: RxStorageWriteError<RxDocType>[];
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* We return a complex object instead of a single array
|
|
181
|
+
* so we are able to add additional fields in the future.
|
|
182
|
+
*/
|
|
183
|
+
export type RxStorageQueryResult<RxDocType> = {
|
|
184
|
+
// the found documents, sort order is important.
|
|
185
|
+
documents: RxDocumentData<RxDocType>[];
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
export type RxStorageCountResult = {
|
|
189
|
+
count: number;
|
|
190
|
+
/**
|
|
191
|
+
* Returns the mode which was used by the storage
|
|
192
|
+
* to count the documents.
|
|
193
|
+
* If this returns 'slow', RxDB will throw by default
|
|
194
|
+
* if 'allowSlowCount' is not set.
|
|
195
|
+
*/
|
|
196
|
+
mode: 'fast' | 'slow';
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
export type RxStorageInstanceCreationParams<RxDocType, InstanceCreationOptions> = {
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* A string to uniquely identify the instance of the JavaScript object
|
|
203
|
+
* of the RxDatabase where this RxStorageInstance belongs to.
|
|
204
|
+
* In most cases you would use RxDatabase.token here.
|
|
205
|
+
*
|
|
206
|
+
* This is used so that we can add caching or reuse stuff that belongs to the same RxDatabase.
|
|
207
|
+
* For example the BroadcastChannel that is used for event propagation between multiple browser tabs
|
|
208
|
+
* is cached by this token.
|
|
209
|
+
*
|
|
210
|
+
* In theory we could just use the databaseName for that. But to make it easier in unit tests
|
|
211
|
+
* to simulate cross-tab usage, we cannot assume that the databaseName is unique in a single
|
|
212
|
+
* JavaScript process. Therefore we use the instance token instead.
|
|
213
|
+
*/
|
|
214
|
+
databaseInstanceToken: string;
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
databaseName: string;
|
|
218
|
+
collectionName: string;
|
|
219
|
+
schema: RxJsonSchema<RxDocumentData<RxDocType>>;
|
|
220
|
+
options: InstanceCreationOptions;
|
|
221
|
+
/**
|
|
222
|
+
* If multiInstance is true, there can be more
|
|
223
|
+
* then one instance of the database, for example
|
|
224
|
+
* when multiple browser tabs exist or more then one Node.js
|
|
225
|
+
* process relies on the same storage.
|
|
226
|
+
*/
|
|
227
|
+
multiInstance: boolean;
|
|
228
|
+
/**
|
|
229
|
+
* Typed as `any` because different encryption plugins
|
|
230
|
+
* may use passwords that are not strings.
|
|
231
|
+
*/
|
|
232
|
+
password?: string | any;
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Some storages can do additional checks
|
|
236
|
+
* that are performance expensive
|
|
237
|
+
* and should only be done in dev-mode.
|
|
238
|
+
*/
|
|
239
|
+
devMode: boolean;
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
export type ChangeStreamOptions = {
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Sequence number of the first event to start with.
|
|
246
|
+
* If you want to get all ongoing events,
|
|
247
|
+
* first get the latest sequence number and input it here.
|
|
248
|
+
*
|
|
249
|
+
* Optional on changeStream,
|
|
250
|
+
* will start from the newest sequence.
|
|
251
|
+
*/
|
|
252
|
+
startSequence?: number;
|
|
253
|
+
/**
|
|
254
|
+
* limits the amount of results
|
|
255
|
+
*/
|
|
256
|
+
limit?: number;
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* In the past we handles each RxChangeEvent by its own.
|
|
261
|
+
* But it has been shown that this take way more performance then needed,
|
|
262
|
+
* especially when the events get transferred over a data layer
|
|
263
|
+
* like with WebWorkers or the BroadcastChannel.
|
|
264
|
+
* So we now process events as bulks internally.
|
|
265
|
+
*/
|
|
266
|
+
export type EventBulk<EventType, CheckpointType> = {
|
|
267
|
+
/**
|
|
268
|
+
* Unique id of the bulk,
|
|
269
|
+
* used to detect duplicate bulks
|
|
270
|
+
* that have already been processed.
|
|
271
|
+
*/
|
|
272
|
+
id: string;
|
|
273
|
+
events: EventType[];
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Required for replication.
|
|
277
|
+
* Passing this checkpoint into getChangedDocumentsSince()
|
|
278
|
+
* must return all items that have been modified AFTER this write event.
|
|
279
|
+
*/
|
|
280
|
+
checkpoint: CheckpointType;
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* The context that was given at the call to bulkWrite()
|
|
284
|
+
* that caused this EventBulk.
|
|
285
|
+
*/
|
|
286
|
+
context: string;
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
export type ChangeStreamEvent<DocType> = ChangeEvent<RxDocumentData<DocType>> & {
|
|
290
|
+
/**
|
|
291
|
+
* An integer that is increasing
|
|
292
|
+
* and unique per event.
|
|
293
|
+
* Can be used to sort events or get information
|
|
294
|
+
* about how many events there are.
|
|
295
|
+
*/
|
|
296
|
+
sequence: number;
|
|
297
|
+
/**
|
|
298
|
+
* The value of the primary key
|
|
299
|
+
* of the changed document
|
|
300
|
+
*/
|
|
301
|
+
id: string;
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
export type RxStorageChangeEvent<RxDocType> = Omit<RxChangeEvent<RxDocType>, 'isLocal' | 'collectionName'>;
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* An example for how a RxStorage checkpoint can look like.
|
|
308
|
+
* NOTICE: Not all implementations use this type.
|
|
309
|
+
*/
|
|
310
|
+
export type RxStorageDefaultCheckpoint = {
|
|
311
|
+
id: string;
|
|
312
|
+
lwt: number;
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
export type CategorizeBulkWriteRowsOutput<RxDocType> = {
|
|
319
|
+
bulkInsertDocs: BulkWriteRowProcessed<RxDocType>[];
|
|
320
|
+
bulkUpdateDocs: BulkWriteRowProcessed<RxDocType>[];
|
|
321
|
+
|
|
322
|
+
errors: RxStorageWriteError<RxDocType>[];
|
|
323
|
+
eventBulk: EventBulk<RxStorageChangeEvent<RxDocumentData<RxDocType>>, any>;
|
|
324
|
+
attachmentsAdd: {
|
|
325
|
+
documentId: string;
|
|
326
|
+
attachmentId: string;
|
|
327
|
+
attachmentData: RxAttachmentWriteData;
|
|
328
|
+
digest: string;
|
|
329
|
+
}[];
|
|
330
|
+
attachmentsRemove: {
|
|
331
|
+
documentId: string;
|
|
332
|
+
attachmentId: string;
|
|
333
|
+
digest: string;
|
|
334
|
+
}[];
|
|
335
|
+
attachmentsUpdate: {
|
|
336
|
+
documentId: string;
|
|
337
|
+
attachmentId: string;
|
|
338
|
+
attachmentData: RxAttachmentWriteData;
|
|
339
|
+
digest: string;
|
|
340
|
+
}[];
|
|
341
|
+
/**
|
|
342
|
+
* Contains the non-error document row that
|
|
343
|
+
* has the newest _meta.lwt time.
|
|
344
|
+
* Empty if no successful write exists.
|
|
345
|
+
*/
|
|
346
|
+
newestRow?: BulkWriteRowProcessed<RxDocType>;
|
|
347
|
+
};
|