-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathOplogEntry.ts
More file actions
50 lines (46 loc) · 1.21 KB
/
OplogEntry.ts
File metadata and controls
50 lines (46 loc) · 1.21 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
import { OpId } from './CrudEntry.js';
import { OpType, OpTypeJSON } from './OpType.js';
export interface OplogEntryJSON {
checksum: number;
data?: string;
object_id?: string;
object_type?: string;
op_id: string;
op: OpTypeJSON;
subkey?: string;
}
export class OplogEntry {
static fromRow(row: OplogEntryJSON) {
return new OplogEntry(
row.op_id,
OpType.fromJSON(row.op),
row.checksum,
row.subkey,
row.object_type,
row.object_id,
row.data
);
}
constructor(
public op_id: OpId,
public op: OpType,
public checksum: number,
public subkey?: string,
public object_type?: string,
public object_id?: string,
public data?: string
) {}
toJSON(fixedKeyEncoding = false): OplogEntryJSON {
return {
op_id: this.op_id,
op: this.op.toJSON(),
object_type: this.object_type,
object_id: this.object_id,
checksum: this.checksum,
data: this.data,
// Older versions of the JS SDK used to always JSON.stringify here. That has always been wrong,
// but we need to migrate gradually to not break existing databases.
subkey: fixedKeyEncoding ? this.subkey : JSON.stringify(this.subkey)
};
}
}