-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathBucketStorageAdapter.ts
More file actions
110 lines (90 loc) · 2.73 KB
/
Copy pathBucketStorageAdapter.ts
File metadata and controls
110 lines (90 loc) · 2.73 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import { BaseListener, BaseObserver, Disposable } from '../../../utils/BaseObserver.js';
import { CrudBatch } from './CrudBatch.js';
import { CrudEntry, OpId } from './CrudEntry.js';
import { SyncDataBatch } from './SyncDataBatch.js';
export interface BucketDescription {
name: string;
priority: number;
}
export interface Checkpoint {
last_op_id: OpId;
buckets: BucketChecksum[];
write_checkpoint?: string;
}
export interface BucketState {
bucket: string;
op_id: string;
}
export interface ChecksumCache {
checksums: Map<string, { checksum: BucketChecksum; last_op_id: OpId }>;
lastOpId: OpId;
}
export interface SyncLocalDatabaseResult {
ready: boolean;
checkpointValid: boolean;
checkpointFailures?: string[];
}
export type SavedProgress = {
atLast: number;
sinceLast: number;
};
export type BucketOperationProgress = Record<string, SavedProgress>;
export interface BucketChecksum {
bucket: string;
priority?: number;
/**
* 32-bit unsigned hash.
*/
checksum: number;
/**
* Count of operations - informational only.
*/
count?: number;
}
export enum PSInternalTable {
DATA = 'ps_data',
CRUD = 'ps_crud',
BUCKETS = 'ps_buckets',
OPLOG = 'ps_oplog',
UNTYPED = 'ps_untyped'
}
export enum PowerSyncControlCommand {
PROCESS_TEXT_LINE = 'line_text',
PROCESS_BSON_LINE = 'line_binary',
STOP = 'stop',
START = 'start',
NOTIFY_TOKEN_REFRESHED = 'refreshed_token',
NOTIFY_CRUD_UPLOAD_COMPLETED = 'completed_upload'
}
export interface BucketStorageListener extends BaseListener {
crudUpdate: () => void;
}
export interface BucketStorageAdapter extends BaseObserver<BucketStorageListener>, Disposable {
init(): Promise<void>;
saveSyncData(batch: SyncDataBatch, fixedKeyFormat?: boolean): Promise<void>;
removeBuckets(buckets: string[]): Promise<void>;
setTargetCheckpoint(checkpoint: Checkpoint): Promise<void>;
startSession(): void;
getBucketStates(): Promise<BucketState[]>;
getBucketOperationProgress(): Promise<BucketOperationProgress>;
hasMigratedSubkeys(): Promise<boolean>;
migrateToFixedSubkeys(): Promise<void>;
syncLocalDatabase(
checkpoint: Checkpoint,
priority?: number
): Promise<{ checkpointValid: boolean; ready: boolean; failures?: any[] }>;
nextCrudItem(): Promise<CrudEntry | undefined>;
hasCrud(): Promise<boolean>;
getCrudBatch(limit?: number): Promise<CrudBatch | null>;
hasCompletedSync(): Promise<boolean>;
updateLocalTarget(cb: () => Promise<string>): Promise<boolean>;
getMaxOpId(): string;
/**
* Get an unique client id.
*/
getClientId(): Promise<string>;
/**
* Invokes the `powersync_control` function for the sync client.
*/
control(op: PowerSyncControlCommand, payload: string | ArrayBuffer | null): Promise<string>;
}