@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,46 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
RxDocument
|
|
3
|
+
} from './rx-document.d.ts';
|
|
4
|
+
|
|
5
|
+
declare type Buffer = any;
|
|
6
|
+
|
|
7
|
+
export type RxAttachmentCreator = {
|
|
8
|
+
id: string;
|
|
9
|
+
/**
|
|
10
|
+
* Content type like 'plain/text'
|
|
11
|
+
*/
|
|
12
|
+
type: string;
|
|
13
|
+
/**
|
|
14
|
+
* The data of the attachment.
|
|
15
|
+
*/
|
|
16
|
+
data: Blob;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export type RxAttachmentCreatorBase64 = {
|
|
20
|
+
id: string;
|
|
21
|
+
/**
|
|
22
|
+
* Content type like 'plain/text'
|
|
23
|
+
*/
|
|
24
|
+
type: string;
|
|
25
|
+
/**
|
|
26
|
+
* The data of the attachment as base64.
|
|
27
|
+
*/
|
|
28
|
+
data: string;
|
|
29
|
+
|
|
30
|
+
// must be set manually
|
|
31
|
+
length: number;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export declare class RxAttachment<RxDocumentType, OrmMethods = {}, Reactivity = unknown> {
|
|
35
|
+
readonly doc: RxDocument<RxDocumentType, OrmMethods, Reactivity>;
|
|
36
|
+
readonly id: string;
|
|
37
|
+
readonly type: string;
|
|
38
|
+
readonly length: number;
|
|
39
|
+
readonly digest: string;
|
|
40
|
+
readonly rev: string;
|
|
41
|
+
|
|
42
|
+
remove(): Promise<void>;
|
|
43
|
+
getData(): Promise<Blob>;
|
|
44
|
+
getDataBase64(): Promise<string>;
|
|
45
|
+
getStringData(): Promise<string>;
|
|
46
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
RxDocumentData,
|
|
3
|
+
RxStorageChangeEvent,
|
|
4
|
+
RxStorageDefaultCheckpoint
|
|
5
|
+
} from './rx-storage.d.ts';
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
export type RxChangeEventBase<RxDocType> = {
|
|
9
|
+
operation: 'INSERT' | 'UPDATE' | 'DELETE';
|
|
10
|
+
|
|
11
|
+
readonly documentId: string;
|
|
12
|
+
|
|
13
|
+
// optional, does not exist on changes to localdocs of the database
|
|
14
|
+
readonly collectionName?: string;
|
|
15
|
+
|
|
16
|
+
// true if the event is about a local document, false if not.
|
|
17
|
+
readonly isLocal: boolean;
|
|
18
|
+
|
|
19
|
+
documentData: RxDocumentData<RxDocType>;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export type RxChangeEventInsert<RxDocType> = RxChangeEventBase<RxDocType> & {
|
|
23
|
+
operation: 'INSERT';
|
|
24
|
+
previousDocumentData: undefined;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export type RxChangeEventUpdate<RxDocType> = RxChangeEventBase<RxDocType> & {
|
|
28
|
+
operation: 'UPDATE';
|
|
29
|
+
previousDocumentData: RxDocumentData<RxDocType>;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export type RxChangeEventDelete<RxDocType> = RxChangeEventBase<RxDocType> & {
|
|
33
|
+
operation: 'DELETE';
|
|
34
|
+
previousDocumentData: RxDocumentData<RxDocType>;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export type RxChangeEvent<RxDocType> = RxChangeEventInsert<RxDocType> | RxChangeEventUpdate<RxDocType> | RxChangeEventDelete<RxDocType>;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Internally, all events are processed via bulks
|
|
41
|
+
* to save performance when sending them over a transport layer
|
|
42
|
+
* or de-duplicating them.
|
|
43
|
+
*/
|
|
44
|
+
export type RxChangeEventBulk<RxDocType, CheckpointType = RxStorageDefaultCheckpoint> = {
|
|
45
|
+
/**
|
|
46
|
+
* Unique id of the bulk,
|
|
47
|
+
* used to detect duplicate bulks
|
|
48
|
+
* that have already been processed.
|
|
49
|
+
*/
|
|
50
|
+
id: string;
|
|
51
|
+
|
|
52
|
+
// optional, not given for changes to local documents of a RxDatabase.
|
|
53
|
+
collectionName?: string;
|
|
54
|
+
|
|
55
|
+
isLocal: boolean;
|
|
56
|
+
|
|
57
|
+
events: RxStorageChangeEvent<RxDocType>[];
|
|
58
|
+
/**
|
|
59
|
+
* Required for replication.
|
|
60
|
+
* Passing this checkpoint into getChangedDocumentsSince()
|
|
61
|
+
* must return all items that have been modified AFTER this write event.
|
|
62
|
+
*/
|
|
63
|
+
checkpoint: CheckpointType;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* The context that was given at the call to bulkWrite()
|
|
67
|
+
* that caused this EventBulk.
|
|
68
|
+
*/
|
|
69
|
+
context: string;
|
|
70
|
+
/**
|
|
71
|
+
* Token of the database instance that created the events.
|
|
72
|
+
* Used to determine if the events came from another instance over the BroadcastChannel.
|
|
73
|
+
*/
|
|
74
|
+
databaseToken: string;
|
|
75
|
+
/**
|
|
76
|
+
* The storageToken of the RxDatabase that created the events.
|
|
77
|
+
* Used to ensure we do not process events of other RxDatabases.
|
|
78
|
+
*/
|
|
79
|
+
storageToken: string;
|
|
80
|
+
/**
|
|
81
|
+
* If true, the events belong to some internal stuff like from plugins.
|
|
82
|
+
* Internal events are not emitted to the outside over the .$ Observables.
|
|
83
|
+
*/
|
|
84
|
+
internal: boolean;
|
|
85
|
+
};
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
RxJsonSchema,
|
|
3
|
+
RxDocument,
|
|
4
|
+
MigrationStrategies,
|
|
5
|
+
RxConflictHandler
|
|
6
|
+
} from './index.d.ts';
|
|
7
|
+
import type {
|
|
8
|
+
RxCollectionBase
|
|
9
|
+
} from '../rx-collection.d.ts';
|
|
10
|
+
import type { QueryCache } from '../query-cache.d.ts';
|
|
11
|
+
import type { RxLocalDocumentMutation } from './rx-database.d.ts';
|
|
12
|
+
|
|
13
|
+
export interface KeyFunctionMap {
|
|
14
|
+
[key: string]: Function;
|
|
15
|
+
}
|
|
16
|
+
export interface NumberFunctionMap {
|
|
17
|
+
[key: number]: Function;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Params to create a new collection.
|
|
23
|
+
* Notice the name of the collection is set one level higher
|
|
24
|
+
* when calling addCollections()
|
|
25
|
+
*/
|
|
26
|
+
export type RxCollectionCreator<RxDocType = any> = {
|
|
27
|
+
schema: RxJsonSchema<RxDocType>;
|
|
28
|
+
instanceCreationOptions?: any;
|
|
29
|
+
migrationStrategies?: MigrationStrategies;
|
|
30
|
+
autoMigrate?: boolean;
|
|
31
|
+
statics?: KeyFunctionMap;
|
|
32
|
+
methods?: KeyFunctionMap;
|
|
33
|
+
attachments?: KeyFunctionMap;
|
|
34
|
+
options?: any;
|
|
35
|
+
/**
|
|
36
|
+
* Set this to true if you want to store local documents
|
|
37
|
+
* in the RxCollection instance.
|
|
38
|
+
*/
|
|
39
|
+
localDocuments?: boolean;
|
|
40
|
+
cacheReplacementPolicy?: RxCacheReplacementPolicy;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Depending on which plugins or storage is used,
|
|
44
|
+
* the RxCollection might need a way to resolve conflicts
|
|
45
|
+
* which is done by this conflict handler.
|
|
46
|
+
* If no conflict handler is provided, a master-always-wins handler
|
|
47
|
+
* will be used as default
|
|
48
|
+
*/
|
|
49
|
+
conflictHandler?: RxConflictHandler<RxDocType>;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export type RxCacheReplacementPolicy = (collection: RxCollection, queryCache: QueryCache) => void;
|
|
53
|
+
|
|
54
|
+
export type RxCollectionHookCallback<
|
|
55
|
+
RxDocumentType,
|
|
56
|
+
OrmMethods,
|
|
57
|
+
Reactivity
|
|
58
|
+
> = (
|
|
59
|
+
data: RxDocumentType,
|
|
60
|
+
instance: RxDocument<RxDocumentType, OrmMethods, Reactivity>
|
|
61
|
+
) => void | Promise<void> | any;
|
|
62
|
+
export type RxCollectionHookNoInstance<RxDocumentType> = (data: RxDocumentType) => void | Promise<void> | any;
|
|
63
|
+
export type RxCollectionHookCallbackNonAsync<RxDocumentType, OrmMethods, Reactivity> = (
|
|
64
|
+
data: RxDocumentType,
|
|
65
|
+
instance: RxDocument<RxDocumentType, OrmMethods, Reactivity>
|
|
66
|
+
) => void | any;
|
|
67
|
+
export type RxCollectionHookNoInstanceCallback<
|
|
68
|
+
RxDocumentType,
|
|
69
|
+
OrmMethods,
|
|
70
|
+
Reactivity
|
|
71
|
+
> = (
|
|
72
|
+
data: RxDocumentType,
|
|
73
|
+
instance: RxCollection<RxDocumentType, OrmMethods, Reactivity>
|
|
74
|
+
) => Promise<void> | void | any;
|
|
75
|
+
|
|
76
|
+
export type RxCollection<
|
|
77
|
+
RxDocumentType = any,
|
|
78
|
+
OrmMethods = {},
|
|
79
|
+
StaticMethods = {},
|
|
80
|
+
InstanceCreationOptions = {},
|
|
81
|
+
Reactivity = unknown
|
|
82
|
+
> = StaticMethods &
|
|
83
|
+
RxCollectionBase<InstanceCreationOptions, RxDocumentType, OrmMethods, StaticMethods, Reactivity> &
|
|
84
|
+
RxCollectionGenerated<RxDocumentType, OrmMethods, Reactivity>;
|
|
85
|
+
|
|
86
|
+
export interface RxCollectionGenerated<RxDocumentType = any, OrmMethods = {}, Reactivity = unknown> extends RxLocalDocumentMutation<RxCollection<RxDocumentType, OrmMethods, any, any, Reactivity>> {
|
|
87
|
+
|
|
88
|
+
// HOOKS
|
|
89
|
+
preInsert(fun: RxCollectionHookNoInstanceCallback<RxDocumentType, OrmMethods, Reactivity>, parallel: boolean): void;
|
|
90
|
+
preSave(fun: RxCollectionHookCallback<RxDocumentType, OrmMethods, Reactivity>, parallel: boolean): void;
|
|
91
|
+
preRemove(fun: RxCollectionHookCallback<RxDocumentType, OrmMethods, Reactivity>, parallel: boolean): void;
|
|
92
|
+
postInsert(fun: RxCollectionHookCallback<RxDocumentType, OrmMethods, Reactivity>, parallel: boolean): void;
|
|
93
|
+
postSave(fun: RxCollectionHookCallback<RxDocumentType, OrmMethods, Reactivity>, parallel: boolean): void;
|
|
94
|
+
postRemove(fun: RxCollectionHookCallback<RxDocumentType, OrmMethods, Reactivity>, parallel: boolean): void;
|
|
95
|
+
postCreate(fun: RxCollectionHookCallbackNonAsync<RxDocumentType, OrmMethods, Reactivity>): void;
|
|
96
|
+
|
|
97
|
+
// only inMemory-collections
|
|
98
|
+
awaitPersistence(): Promise<void>;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Previously all properties were typed as any because they could be encrypted.
|
|
103
|
+
* This is no longer needed so the type now preserves the original property types.
|
|
104
|
+
*/
|
|
105
|
+
export type RxDumpCollectionAsAny<T> = T;
|
|
106
|
+
|
|
107
|
+
interface RxDumpCollectionBase {
|
|
108
|
+
name: string;
|
|
109
|
+
passwordHash?: string;
|
|
110
|
+
schemaHash: string;
|
|
111
|
+
}
|
|
112
|
+
export interface RxDumpCollection<RxDocumentType> extends RxDumpCollectionBase {
|
|
113
|
+
docs: RxDocumentType[];
|
|
114
|
+
}
|
|
115
|
+
export interface RxDumpCollectionAny<RxDocumentType> extends RxDumpCollectionBase {
|
|
116
|
+
docs: RxDumpCollectionAsAny<RxDocumentType>[];
|
|
117
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
RxMigrationStatus
|
|
3
|
+
} from '../plugins/migration-schema/index.ts';
|
|
4
|
+
import type { RxJsonSchema } from './rx-schema.d.ts';
|
|
5
|
+
|
|
6
|
+
export type InternalStoreDocType<Data = any> = {
|
|
7
|
+
id: string;
|
|
8
|
+
key: string;
|
|
9
|
+
context: string;
|
|
10
|
+
data: Data;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Stores information about the collections.
|
|
15
|
+
* The collection.name is the 'key' value.
|
|
16
|
+
*/
|
|
17
|
+
export type InternalStoreStorageTokenDocType = InternalStoreDocType<{
|
|
18
|
+
rxdbVersion: string;
|
|
19
|
+
token: string;
|
|
20
|
+
instanceToken: string;
|
|
21
|
+
passwordHash?: string;
|
|
22
|
+
}>;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Stores information about the collections.
|
|
26
|
+
* The collection.name is the 'key' value.
|
|
27
|
+
*/
|
|
28
|
+
export type InternalStoreCollectionDocType = InternalStoreDocType<{
|
|
29
|
+
/**
|
|
30
|
+
* Plain name of the collection
|
|
31
|
+
*/
|
|
32
|
+
name: string;
|
|
33
|
+
schema: RxJsonSchema<any>;
|
|
34
|
+
schemaHash: string;
|
|
35
|
+
version: number;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Storages that are connected to this collection
|
|
39
|
+
* so that when the collection is removed,
|
|
40
|
+
* these storages must also be removed.
|
|
41
|
+
* For example the replication meta storage
|
|
42
|
+
* must be reset when the collection is removed.
|
|
43
|
+
*/
|
|
44
|
+
connectedStorages: {
|
|
45
|
+
collectionName: string;
|
|
46
|
+
schema: RxJsonSchema<any>;
|
|
47
|
+
}[];
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Contains the migration status
|
|
51
|
+
* only if a migration has been started.
|
|
52
|
+
*/
|
|
53
|
+
migrationStatus?: RxMigrationStatus;
|
|
54
|
+
}>;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
RxCollection,
|
|
3
|
+
RxDumpCollection,
|
|
4
|
+
RxDumpCollectionAsAny
|
|
5
|
+
} from './rx-collection.d.ts';
|
|
6
|
+
import type {
|
|
7
|
+
RxDatabaseBase
|
|
8
|
+
} from '../rx-database.d.ts';
|
|
9
|
+
import { Observable } from 'rxjs';
|
|
10
|
+
import type { RxStorage } from './rx-storage.interface.d.ts';
|
|
11
|
+
import type { RxLocalDocument } from './plugins/local-documents.d.ts';
|
|
12
|
+
import type { RxCleanupPolicy } from './plugins/cleanup.d.ts';
|
|
13
|
+
import type { ById, HashFunction } from './util.d.ts';
|
|
14
|
+
import type { RxReactivityFactory } from './plugins/reactivity.d.ts';
|
|
15
|
+
|
|
16
|
+
export interface RxDatabaseCreator<Internals = any, InstanceCreationOptions = any, Reactivity = unknown> {
|
|
17
|
+
storage: RxStorage<Internals, InstanceCreationOptions>;
|
|
18
|
+
instanceCreationOptions?: InstanceCreationOptions;
|
|
19
|
+
name: string;
|
|
20
|
+
/**
|
|
21
|
+
* Typed as `any` because different encryption plugins
|
|
22
|
+
* may use passwords that are not strings.
|
|
23
|
+
*/
|
|
24
|
+
password?: string | any;
|
|
25
|
+
multiInstance?: boolean;
|
|
26
|
+
eventReduce?: boolean;
|
|
27
|
+
ignoreDuplicate?: boolean;
|
|
28
|
+
options?: any;
|
|
29
|
+
cleanupPolicy?: Partial<RxCleanupPolicy>;
|
|
30
|
+
closeDuplicates?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Set this to true if you want to store local documents
|
|
33
|
+
* in the RxDatabase instance.
|
|
34
|
+
*/
|
|
35
|
+
localDocuments?: boolean;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Hash method used to hash strings and json-stringified objects.
|
|
39
|
+
* This hash does not have to be cryptographically secure,
|
|
40
|
+
* but it is very important that is does have not create
|
|
41
|
+
* collisions.
|
|
42
|
+
* Default is the sha256 from crypto.subtle.digest('SHA-256', data)
|
|
43
|
+
*/
|
|
44
|
+
hashFunction?: HashFunction;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* By default, count() queries in 'slow' mode are not allowed.
|
|
48
|
+
*/
|
|
49
|
+
allowSlowCount?: boolean;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Can be used to add a custom reactivity Factory
|
|
53
|
+
* that is used on all getters and values that end with the double $$.
|
|
54
|
+
* For example you can use the signals api of your framework and vuejs ref()
|
|
55
|
+
*/
|
|
56
|
+
reactivity?: RxReactivityFactory<Reactivity>;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export type CollectionsOfDatabase = ById<RxCollection>;
|
|
60
|
+
export type RxDatabase<
|
|
61
|
+
Collections = CollectionsOfDatabase,
|
|
62
|
+
Internals = any,
|
|
63
|
+
InstanceCreationOptions = any,
|
|
64
|
+
Reactivity = any
|
|
65
|
+
> = RxDatabaseBase<
|
|
66
|
+
Internals,
|
|
67
|
+
InstanceCreationOptions,
|
|
68
|
+
Collections,
|
|
69
|
+
Reactivity
|
|
70
|
+
> & Collections & RxDatabaseGenerated<Collections, Reactivity>;
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
export interface RxLocalDocumentMutation<StorageType, Reactivity = unknown> {
|
|
74
|
+
insertLocal<LocalDocType = any>(id: string, data: LocalDocType): Promise<
|
|
75
|
+
RxLocalDocument<StorageType, LocalDocType, Reactivity>
|
|
76
|
+
>;
|
|
77
|
+
upsertLocal<LocalDocType = any>(id: string, data: LocalDocType): Promise<
|
|
78
|
+
RxLocalDocument<StorageType, LocalDocType, Reactivity>
|
|
79
|
+
>;
|
|
80
|
+
getLocal<LocalDocType = any>(id: string): Promise<
|
|
81
|
+
RxLocalDocument<StorageType, LocalDocType, Reactivity> | null
|
|
82
|
+
>;
|
|
83
|
+
getLocal$<LocalDocType = any>(id: string): Observable<
|
|
84
|
+
RxLocalDocument<StorageType, LocalDocType, Reactivity> | null
|
|
85
|
+
>;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface RxDatabaseGenerated<Collections, Reactivity> extends RxLocalDocumentMutation<RxDatabase<Collections, any, any, Reactivity>> { }
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Extract the **DocumentType** of a collection.
|
|
92
|
+
*/
|
|
93
|
+
type ExtractDTcol<P> = P extends RxCollection<infer T> ? T : { [prop: string]: any; };
|
|
94
|
+
|
|
95
|
+
interface RxDumpDatabaseBase {
|
|
96
|
+
instanceToken: string;
|
|
97
|
+
name: string;
|
|
98
|
+
passwordHash: string | null;
|
|
99
|
+
}
|
|
100
|
+
export interface RxDumpDatabase<Col> extends RxDumpDatabaseBase {
|
|
101
|
+
collections: RxDumpCollection<ExtractDTcol<Col[keyof Col]>>[];
|
|
102
|
+
}
|
|
103
|
+
export interface RxDumpDatabaseAny<Col> extends RxDumpDatabaseBase {
|
|
104
|
+
collections: RxDumpCollection<RxDumpCollectionAsAny<ExtractDTcol<Col[keyof Col]>>>[];
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
export type RxCollectionCreatedEvent = {
|
|
110
|
+
type: 'ADDED';
|
|
111
|
+
collection: RxCollection;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
export type RxCollectionClosedEvent = {
|
|
115
|
+
type: 'CLOSED';
|
|
116
|
+
collection: RxCollection;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Fired on RxDatabase.collection$
|
|
121
|
+
*/
|
|
122
|
+
export type RxCollectionEvent =
|
|
123
|
+
| RxCollectionCreatedEvent
|
|
124
|
+
| RxCollectionClosedEvent;
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Observable
|
|
3
|
+
} from 'rxjs';
|
|
4
|
+
|
|
5
|
+
import type {
|
|
6
|
+
RxCollection,
|
|
7
|
+
} from './rx-collection.d.ts';
|
|
8
|
+
import type {
|
|
9
|
+
RxAttachment,
|
|
10
|
+
RxAttachmentCreator,
|
|
11
|
+
RxAttachmentCreatorBase64
|
|
12
|
+
} from './rx-attachment.d.ts';
|
|
13
|
+
import type { RxDocumentData, WithDeleted } from './rx-storage.d.ts';
|
|
14
|
+
import type { RxChangeEvent } from './rx-change-event.d.ts';
|
|
15
|
+
import type { DeepReadonly, MaybePromise, PlainJsonValue } from './util.d.ts';
|
|
16
|
+
import type { UpdateQuery } from './plugins/update.d.ts';
|
|
17
|
+
import type { CRDTEntry } from './plugins/crdt.d.ts';
|
|
18
|
+
import type { Reactified } from './plugins/reactivity.d.ts';
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
export type RxDocument<RxDocumentType = {}, OrmMethods = {}, Reactivity = unknown> = RxDocumentBase<
|
|
23
|
+
RxDocumentType,
|
|
24
|
+
OrmMethods,
|
|
25
|
+
Reactivity
|
|
26
|
+
> & RxDocumentType & OrmMethods & ExtendObservables<RxDocumentType> & ExtendReactivity<RxDocumentType, Reactivity>;
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Extend the base properties by the property$ fields
|
|
31
|
+
* so it knows that RxDocument.age also has RxDocument.age$ which is
|
|
32
|
+
* an observable.
|
|
33
|
+
* TODO how to do this for the nested fields?
|
|
34
|
+
*/
|
|
35
|
+
type ExtendObservables<RxDocumentType> = {
|
|
36
|
+
[P in keyof RxDocumentType as `${string & P}$`]: Observable<RxDocumentType[P]>;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
type ExtendReactivity<RxDocumentType, Reactivity> = {
|
|
40
|
+
[P in keyof RxDocumentType as `${string & P}$$`]: Reactified<Reactivity, RxDocumentType[P]>;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The public facing modify update function.
|
|
45
|
+
* It only gets the document parts as input, that
|
|
46
|
+
* are mutateable by the user.
|
|
47
|
+
*/
|
|
48
|
+
export type ModifyFunction<RxDocumentType> = (
|
|
49
|
+
doc: WithDeleted<RxDocumentType>
|
|
50
|
+
) => MaybePromise<WithDeleted<RxDocumentType>> | MaybePromise<RxDocumentType>;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Meta data that is attached to each document by RxDB.
|
|
54
|
+
*/
|
|
55
|
+
export type RxDocumentMeta = {
|
|
56
|
+
/**
|
|
57
|
+
* Last write time.
|
|
58
|
+
* Unix epoch in milliseconds.
|
|
59
|
+
*/
|
|
60
|
+
lwt: number;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* The replication plugins "tags" the origin
|
|
64
|
+
* of writes to later know if a write came from
|
|
65
|
+
* the replication or was done locally.
|
|
66
|
+
*/
|
|
67
|
+
o?: {
|
|
68
|
+
hash: string;
|
|
69
|
+
_rev: number;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Any other value can be attached to the _meta data.
|
|
74
|
+
* Mostly done by plugins to mark documents.
|
|
75
|
+
*/
|
|
76
|
+
[k: string]: PlainJsonValue | undefined;
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export declare interface RxDocumentBase<RxDocType, OrmMethods = {}, Reactivity = unknown> {
|
|
82
|
+
isInstanceOfRxDocument: true;
|
|
83
|
+
collection: RxCollection<RxDocType, OrmMethods, Reactivity>;
|
|
84
|
+
readonly deleted: boolean;
|
|
85
|
+
|
|
86
|
+
readonly $: Observable<RxDocument<RxDocType, OrmMethods, Reactivity>>;
|
|
87
|
+
readonly $$: Reactified<Reactivity, RxDocument<RxDocType, OrmMethods, Reactivity>>;
|
|
88
|
+
readonly deleted$: Observable<boolean>;
|
|
89
|
+
readonly deleted$$: Reactified<Reactivity, boolean>;
|
|
90
|
+
|
|
91
|
+
readonly primary: string;
|
|
92
|
+
readonly allAttachments$: Observable<RxAttachment<RxDocType, OrmMethods, Reactivity>[]>;
|
|
93
|
+
|
|
94
|
+
// internal things
|
|
95
|
+
_data: RxDocumentData<RxDocType>;
|
|
96
|
+
primaryPath: string;
|
|
97
|
+
revision: string;
|
|
98
|
+
/**
|
|
99
|
+
* Used to de-duplicate the enriched property objects
|
|
100
|
+
* of the document. Lazily initialized on first property access.
|
|
101
|
+
*/
|
|
102
|
+
_propertyCache: Map<string, any> | undefined;
|
|
103
|
+
$emit(cE: RxChangeEvent<RxDocType>): void;
|
|
104
|
+
_saveData(newData: any, oldData: RxDocumentData<RxDocType>): Promise<RxDocument<RxDocType, OrmMethods, Reactivity>>;
|
|
105
|
+
// /internal things
|
|
106
|
+
|
|
107
|
+
// Returns the latest state of the document
|
|
108
|
+
getLatest(): RxDocument<RxDocType, OrmMethods, Reactivity>;
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
get$(path: string): Observable<any>;
|
|
112
|
+
get$$(path: string): Reactified<Reactivity, any>;
|
|
113
|
+
get(objPath: string): DeepReadonly<any>;
|
|
114
|
+
populate(objPath: string): Promise<RxDocument<RxDocType, OrmMethods, Reactivity> | any | null>;
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* mutate the document with a function
|
|
118
|
+
*/
|
|
119
|
+
modify(mutationFunction: ModifyFunction<RxDocType>, context?: string): Promise<RxDocument<RxDocType, OrmMethods, Reactivity>>;
|
|
120
|
+
incrementalModify(mutationFunction: ModifyFunction<RxDocType>, context?: string): Promise<RxDocument<RxDocType, OrmMethods, Reactivity>>;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* patches the given properties
|
|
124
|
+
*/
|
|
125
|
+
patch(patch: Partial<RxDocType>): Promise<RxDocument<RxDocType, OrmMethods, Reactivity>>;
|
|
126
|
+
incrementalPatch(patch: Partial<RxDocType>): Promise<RxDocument<RxDocType, OrmMethods, Reactivity>>;
|
|
127
|
+
|
|
128
|
+
update(updateObj: UpdateQuery<RxDocType>): Promise<RxDocument<RxDocType, OrmMethods, Reactivity>>;
|
|
129
|
+
incrementalUpdate(updateObj: UpdateQuery<RxDocType>): Promise<RxDocument<RxDocType, OrmMethods, Reactivity>>;
|
|
130
|
+
|
|
131
|
+
updateCRDT(updateObj: CRDTEntry<RxDocType> | CRDTEntry<RxDocType>[]): Promise<RxDocument<RxDocType, OrmMethods, Reactivity>>;
|
|
132
|
+
|
|
133
|
+
remove(): Promise<RxDocument<RxDocType, OrmMethods, Reactivity>>;
|
|
134
|
+
incrementalRemove(): Promise<RxDocument<RxDocType, OrmMethods, Reactivity>>;
|
|
135
|
+
|
|
136
|
+
// only for temporary documents
|
|
137
|
+
set(objPath: string, value: any): RxDocument<RxDocType, OrmMethods, Reactivity>;
|
|
138
|
+
save(): Promise<boolean>;
|
|
139
|
+
|
|
140
|
+
// attachments
|
|
141
|
+
putAttachment(
|
|
142
|
+
creator: RxAttachmentCreator
|
|
143
|
+
): Promise<RxAttachment<RxDocType, OrmMethods, Reactivity>>;
|
|
144
|
+
putAttachmentBase64(
|
|
145
|
+
creator: RxAttachmentCreatorBase64
|
|
146
|
+
): Promise<RxAttachment<RxDocType, OrmMethods, Reactivity>>;
|
|
147
|
+
putAttachments(
|
|
148
|
+
creators: RxAttachmentCreator[]
|
|
149
|
+
): Promise<RxAttachment<RxDocType, OrmMethods, Reactivity>[]>;
|
|
150
|
+
getAttachment(id: string): RxAttachment<RxDocType, OrmMethods, Reactivity> | null;
|
|
151
|
+
allAttachments(): RxAttachment<RxDocType, OrmMethods, Reactivity>[];
|
|
152
|
+
|
|
153
|
+
toJSON(withRevAndAttachments: true): DeepReadonly<RxDocumentData<RxDocType>>;
|
|
154
|
+
toJSON(withRevAndAttachments?: false): DeepReadonly<RxDocType>;
|
|
155
|
+
|
|
156
|
+
toMutableJSON(withRevAndAttachments: true): RxDocumentData<RxDocType>;
|
|
157
|
+
toMutableJSON(withRevAndAttachments?: false): RxDocType;
|
|
158
|
+
|
|
159
|
+
close(): void;
|
|
160
|
+
}
|