-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathVersionedPowerSyncMongoBase.ts
More file actions
80 lines (62 loc) · 2.23 KB
/
Copy pathVersionedPowerSyncMongoBase.ts
File metadata and controls
80 lines (62 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import { mongo } from '@powersync/lib-service-mongodb';
import { DO_NOT_LOG } from '@powersync/lib-services-framework';
import { PowerSyncMongo } from '../db.js';
import { CommonSourceTableDocument, StorageConfig } from '../models.js';
export abstract class BaseVersionedPowerSyncMongo {
readonly client: mongo.MongoClient;
readonly db: mongo.Db;
readonly storageConfig: StorageConfig;
[DO_NOT_LOG] = true;
constructor(
protected readonly upstream: PowerSyncMongo,
storageConfig: StorageConfig
) {
this.client = upstream.client;
this.db = upstream.db;
this.storageConfig = storageConfig;
}
get bucket_data() {
return this.upstream.bucket_data;
}
get op_id_sequence() {
return this.upstream.op_id_sequence;
}
get sync_rules() {
return this.upstream.sync_rules;
}
get custom_write_checkpoints() {
return this.upstream.custom_write_checkpoints;
}
get write_checkpoints() {
return this.upstream.write_checkpoints;
}
get instance() {
return this.upstream.instance;
}
get locks() {
return this.upstream.locks;
}
get checkpoint_events() {
return this.upstream.checkpoint_events;
}
get connection_report_events() {
return this.upstream.connection_report_events;
}
notifyCheckpoint() {
return this.upstream.notifyCheckpoint();
}
protected sourceRecordsCollectionName(replicationStreamId: number, sourceTableId: mongo.ObjectId) {
return this.upstream.sourceRecordsCollectionName(replicationStreamId, sourceTableId);
}
protected sourceTableCollectionName(replicationStreamId: number) {
return this.upstream.sourceTableCollectionName(replicationStreamId);
}
protected async listCollectionsByPrefix<T extends mongo.Document>(prefix: string): Promise<mongo.Collection<T>[]> {
const collections = await this.db.listCollections({ name: { $regex: `^${prefix}` } }, { nameOnly: true }).toArray();
return collections
.filter((collection) => collection.name.startsWith(prefix))
.map((collection) => this.db.collection<T>(collection.name));
}
abstract commonSourceTables(replicationStreamId: number): mongo.Collection<CommonSourceTableDocument>;
abstract initializeStreamStorage(replicationStreamId: number): Promise<void>;
}