@litebackup/sdk 0.0.0-stage → 0.3.19
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/src/backup.d.ts +66 -0
- package/dist/src/backup.js +139 -0
- package/dist/src/case.d.ts +9 -0
- package/dist/src/case.js +14 -0
- package/dist/src/client.d.ts +174 -0
- package/dist/src/client.js +284 -0
- package/dist/src/duration.d.ts +4 -0
- package/dist/src/duration.js +15 -0
- package/dist/src/failover.d.ts +69 -0
- package/dist/src/failover.js +161 -0
- package/dist/src/generated/client.d.ts +1736 -0
- package/dist/src/generated/client.js +5 -0
- package/dist/src/helpers.d.ts +38 -0
- package/dist/src/helpers.js +80 -0
- package/dist/src/index.d.ts +17 -0
- package/dist/src/index.js +8 -0
- package/dist/src/launch.d.ts +27 -0
- package/dist/src/launch.js +98 -0
- package/dist/src/paths.d.ts +15 -0
- package/dist/src/paths.js +42 -0
- package/dist/src/release.d.ts +39 -0
- package/dist/src/release.js +67 -0
- package/dist/src/socket.d.ts +20 -0
- package/dist/src/socket.js +44 -0
- package/dist/src/types.d.ts +41 -0
- package/dist/src/types.js +16 -0
- package/package.json +36 -4
- package/README.md +0 -3
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { type Litebackup } from "./client.js";
|
|
2
|
+
import { type Duration } from "./duration.js";
|
|
3
|
+
import { type BackupInfo, type Durability } from "./types.js";
|
|
4
|
+
/** A better-sqlite3 Database, read by duck typing; the SDK never imports better-sqlite3. */
|
|
5
|
+
export interface SQLiteHandle {
|
|
6
|
+
readonly name: string;
|
|
7
|
+
readonly memory: boolean;
|
|
8
|
+
readonly open: boolean;
|
|
9
|
+
}
|
|
10
|
+
/** A database path, relative or absolute, or a better-sqlite3 handle. */
|
|
11
|
+
export type BackupSource = string | SQLiteHandle;
|
|
12
|
+
/** Options for backup. */
|
|
13
|
+
export interface BackupOptions {
|
|
14
|
+
/** Sets the database name outright; it must be a valid name. */
|
|
15
|
+
name?: string;
|
|
16
|
+
/** Goes before the normalized file name, such as "app/". */
|
|
17
|
+
prefix?: string;
|
|
18
|
+
/** Makes the start request itself wait until the server, or the bucket, holds the first version; ready resolves then. */
|
|
19
|
+
wait?: "none" | Durability;
|
|
20
|
+
/** Bound on that wait. */
|
|
21
|
+
timeout?: Duration;
|
|
22
|
+
/** When positive, offload the least recently changed idle databases past this count once the bucket holds them. */
|
|
23
|
+
maximumLocalDatabases?: number;
|
|
24
|
+
/** Join token for the shared client; defaults to LITEBACKUP_TOKEN. Used only by the package-level backup(). */
|
|
25
|
+
token?: string;
|
|
26
|
+
/** Session for the shared client. Used only by the package-level backup(). */
|
|
27
|
+
session?: string;
|
|
28
|
+
}
|
|
29
|
+
/** Sets how often wait("cloud") polls, for tests. @internal */
|
|
30
|
+
export declare function setDurabilityPoll(interval: number): void;
|
|
31
|
+
/** Turns a backup source into the absolute path the daemon needs. */
|
|
32
|
+
export declare function sourcePath(source: BackupSource): string;
|
|
33
|
+
/** The name the daemon gives a single file: the file name, lowercased with other characters turned into -, after the prefix. */
|
|
34
|
+
export declare function expectedName(path: string, options: Pick<BackupOptions, "name" | "prefix">): string;
|
|
35
|
+
/**
|
|
36
|
+
* A running backup. backup() returns it at once; the start request runs in
|
|
37
|
+
* the background. `ready` resolves with the daemon's answer, or rejects with
|
|
38
|
+
* its error, such as name_in_use. wait() and stop() await `ready` first, so
|
|
39
|
+
* they reject with the same error. Nothing swallows a failed start: when no
|
|
40
|
+
* code awaits `ready`, wait(), or stop(), Node reports the rejection as
|
|
41
|
+
* unhandled.
|
|
42
|
+
*/
|
|
43
|
+
export declare class Backup {
|
|
44
|
+
/** The database name: the expected name until ready resolves, then the daemon's. Empty for a glob. */
|
|
45
|
+
name: string;
|
|
46
|
+
/** The absolute path or glob. */
|
|
47
|
+
readonly path: string;
|
|
48
|
+
/** The backup's ID on this machine, once ready resolved. */
|
|
49
|
+
id: string | undefined;
|
|
50
|
+
/** Resolves once the daemon started the backup. */
|
|
51
|
+
readonly ready: Promise<BackupInfo>;
|
|
52
|
+
/** @internal */
|
|
53
|
+
private readonly client;
|
|
54
|
+
/** Use backup(); it starts the backup. */
|
|
55
|
+
constructor(client: Promise<Litebackup>, source: BackupSource, options: BackupOptions);
|
|
56
|
+
/**
|
|
57
|
+
* Resolves once every change written before the call is on the server
|
|
58
|
+
* ("server", the default) or in the bucket too ("cloud"). Rejects with the
|
|
59
|
+
* start error when the backup never started.
|
|
60
|
+
*/
|
|
61
|
+
wait(durability?: Durability, options?: {
|
|
62
|
+
signal?: AbortSignal;
|
|
63
|
+
}): Promise<void>;
|
|
64
|
+
/** Stops the backup and releases its write locks. The files and their backups stay. */
|
|
65
|
+
stop(): Promise<void>;
|
|
66
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { basename } from "node:path";
|
|
2
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
3
|
+
import { absolutePath } from "./client.js";
|
|
4
|
+
import { milliseconds } from "./duration.js";
|
|
5
|
+
import { LitebackupError } from "./types.js";
|
|
6
|
+
/** How often wait("cloud") reads a database's status. */
|
|
7
|
+
let durabilityPoll = 500;
|
|
8
|
+
/** Sets how often wait("cloud") polls, for tests. @internal */
|
|
9
|
+
export function setDurabilityPoll(interval) {
|
|
10
|
+
durabilityPoll = interval;
|
|
11
|
+
}
|
|
12
|
+
/** Reports whether a value looks like a better-sqlite3 Database. */
|
|
13
|
+
function isSQLiteHandle(value) {
|
|
14
|
+
const candidate = value;
|
|
15
|
+
return typeof candidate === "object" && candidate !== null && typeof candidate.name === "string" && typeof candidate.memory === "boolean" && typeof candidate.open === "boolean";
|
|
16
|
+
}
|
|
17
|
+
/** Turns a backup source into the absolute path the daemon needs. */
|
|
18
|
+
export function sourcePath(source) {
|
|
19
|
+
if (typeof source === "string") {
|
|
20
|
+
if (!source) {
|
|
21
|
+
throw new LitebackupError("invalid_argument", "backup needs a path", 0);
|
|
22
|
+
}
|
|
23
|
+
return absolutePath(source);
|
|
24
|
+
}
|
|
25
|
+
if (!isSQLiteHandle(source)) {
|
|
26
|
+
throw new LitebackupError("invalid_argument", "backup takes a path or a better-sqlite3 database", 0);
|
|
27
|
+
}
|
|
28
|
+
if (source.memory || source.name === "" || source.name === ":memory:") {
|
|
29
|
+
throw new LitebackupError("invalid_argument", "an in-memory database has no file to back up; open it from a path", 0);
|
|
30
|
+
}
|
|
31
|
+
return absolutePath(source.name);
|
|
32
|
+
}
|
|
33
|
+
/** The name the daemon gives a single file: the file name, lowercased with other characters turned into -, after the prefix. */
|
|
34
|
+
export function expectedName(path, options) {
|
|
35
|
+
if (options.name) {
|
|
36
|
+
return options.name;
|
|
37
|
+
}
|
|
38
|
+
if (/[*?[]/.test(basename(path))) {
|
|
39
|
+
return "";
|
|
40
|
+
}
|
|
41
|
+
// The daemon ends a prefix with / when it lacks one.
|
|
42
|
+
let prefix = options.prefix ?? "";
|
|
43
|
+
if (prefix && !prefix.endsWith("/")) {
|
|
44
|
+
prefix += "/";
|
|
45
|
+
}
|
|
46
|
+
return prefix + basename(path).toLowerCase().replace(/[^a-z0-9._-]/g, "-");
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* A running backup. backup() returns it at once; the start request runs in
|
|
50
|
+
* the background. `ready` resolves with the daemon's answer, or rejects with
|
|
51
|
+
* its error, such as name_in_use. wait() and stop() await `ready` first, so
|
|
52
|
+
* they reject with the same error. Nothing swallows a failed start: when no
|
|
53
|
+
* code awaits `ready`, wait(), or stop(), Node reports the rejection as
|
|
54
|
+
* unhandled.
|
|
55
|
+
*/
|
|
56
|
+
export class Backup {
|
|
57
|
+
/** The database name: the expected name until ready resolves, then the daemon's. Empty for a glob. */
|
|
58
|
+
name;
|
|
59
|
+
/** The absolute path or glob. */
|
|
60
|
+
path;
|
|
61
|
+
/** The backup's ID on this machine, once ready resolved. */
|
|
62
|
+
id;
|
|
63
|
+
/** Resolves once the daemon started the backup. */
|
|
64
|
+
ready;
|
|
65
|
+
/** @internal */
|
|
66
|
+
client;
|
|
67
|
+
/** Use backup(); it starts the backup. */
|
|
68
|
+
constructor(client, source, options) {
|
|
69
|
+
this.path = sourcePath(source);
|
|
70
|
+
this.name = expectedName(this.path, options);
|
|
71
|
+
this.client = client;
|
|
72
|
+
const body = { path: this.path };
|
|
73
|
+
if (options.name) {
|
|
74
|
+
body.name = options.name;
|
|
75
|
+
}
|
|
76
|
+
if (options.prefix) {
|
|
77
|
+
body.prefix = options.prefix;
|
|
78
|
+
}
|
|
79
|
+
if (options.wait) {
|
|
80
|
+
body.wait = options.wait;
|
|
81
|
+
}
|
|
82
|
+
if (options.timeout !== undefined) {
|
|
83
|
+
body.timeout_millis = milliseconds(options.timeout);
|
|
84
|
+
}
|
|
85
|
+
if (options.maximumLocalDatabases !== undefined) {
|
|
86
|
+
body.maximum_local_databases = options.maximumLocalDatabases;
|
|
87
|
+
}
|
|
88
|
+
this.ready = client.then(async (litebackup) => {
|
|
89
|
+
const info = (await litebackup.call("POST", "/v1/backups/start", body));
|
|
90
|
+
this.id = info.id;
|
|
91
|
+
if (info.name) {
|
|
92
|
+
this.name = info.name;
|
|
93
|
+
}
|
|
94
|
+
else if (info.databases.length === 1 && this.name) {
|
|
95
|
+
this.name = info.databases[0].name;
|
|
96
|
+
}
|
|
97
|
+
return info;
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Resolves once every change written before the call is on the server
|
|
102
|
+
* ("server", the default) or in the bucket too ("cloud"). Rejects with the
|
|
103
|
+
* start error when the backup never started.
|
|
104
|
+
*/
|
|
105
|
+
async wait(durability = "server", options = {}) {
|
|
106
|
+
if (durability !== "server" && durability !== "cloud") {
|
|
107
|
+
throw new LitebackupError("invalid_argument", `wait for server or cloud, not ${JSON.stringify(durability)}`, 0);
|
|
108
|
+
}
|
|
109
|
+
const started = await this.ready;
|
|
110
|
+
const litebackup = await this.client;
|
|
111
|
+
const listed = (await litebackup.backups.list()).find((backup) => backup.id === started.id);
|
|
112
|
+
const names = (listed ?? started).databases.map((database) => database.name);
|
|
113
|
+
if (names.length === 0 && this.name) {
|
|
114
|
+
names.push(this.name);
|
|
115
|
+
}
|
|
116
|
+
for (const name of names) {
|
|
117
|
+
const synced = await litebackup.sync(name);
|
|
118
|
+
if (durability === "cloud") {
|
|
119
|
+
for (;;) {
|
|
120
|
+
options.signal?.throwIfAborted();
|
|
121
|
+
const status = await litebackup.database(name);
|
|
122
|
+
if (status.syncedCloud.version >= synced.syncedServer.version) {
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
if (status.state === "error" && status.lastError) {
|
|
126
|
+
throw new LitebackupError("sync_failed", status.lastError, 0);
|
|
127
|
+
}
|
|
128
|
+
await delay(durabilityPoll, undefined, { signal: options.signal });
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/** Stops the backup and releases its write locks. The files and their backups stay. */
|
|
134
|
+
async stop() {
|
|
135
|
+
const started = await this.ready;
|
|
136
|
+
const litebackup = await this.client;
|
|
137
|
+
await litebackup.backups.stop({ id: started.id });
|
|
138
|
+
}
|
|
139
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Turns a snake_case key into camelCase. */
|
|
2
|
+
type CamelKey<S extends string> = S extends `${infer Head}_${infer Tail}` ? `${Head}${Capitalize<CamelKey<Tail>>}` : S;
|
|
3
|
+
/** A socket API type with every key in camelCase, as the SDK returns it. */
|
|
4
|
+
export type Camelize<T> = T extends readonly (infer Item)[] ? Camelize<Item>[] : T extends object ? {
|
|
5
|
+
[Key in keyof T as Key extends string ? CamelKey<Key> : Key]: Camelize<T[Key]>;
|
|
6
|
+
} : T;
|
|
7
|
+
/** Converts every key of a decoded JSON answer from snake_case to camelCase. */
|
|
8
|
+
export declare function camelize<T>(value: T): Camelize<T>;
|
|
9
|
+
export {};
|
package/dist/src/case.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Converts every key of a decoded JSON answer from snake_case to camelCase. */
|
|
2
|
+
export function camelize(value) {
|
|
3
|
+
if (Array.isArray(value)) {
|
|
4
|
+
return value.map((item) => camelize(item));
|
|
5
|
+
}
|
|
6
|
+
if (value !== null && typeof value === "object") {
|
|
7
|
+
const converted = {};
|
|
8
|
+
for (const [key, item] of Object.entries(value)) {
|
|
9
|
+
converted[key.replace(/_([a-z0-9])/g, (_match, letter) => letter.toUpperCase())] = camelize(item);
|
|
10
|
+
}
|
|
11
|
+
return converted;
|
|
12
|
+
}
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { Backup, type BackupOptions, type BackupSource } from "./backup.js";
|
|
2
|
+
import { type Duration } from "./duration.js";
|
|
3
|
+
import { Failover, type FailoverOptions } from "./failover.js";
|
|
4
|
+
import { type AcquireResult, type BackupInfo, type Conflict, type DatabaseStatus, type Durability, type EventList, type LitebackupEvent, type ReleaseResult, type ReplicaList, type RestoreResult, type ShutdownResult, type Status, type Version, type WriteProtection, type Writer } from "./types.js";
|
|
5
|
+
/** Options for connecting to a Litebackup session. */
|
|
6
|
+
export interface ConnectOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Join token, TOKEN@HOST, the daemon joins with on its first start;
|
|
9
|
+
* defaults to LITEBACKUP_TOKEN. A daemon that already joined keeps its join.
|
|
10
|
+
*/
|
|
11
|
+
token?: string;
|
|
12
|
+
/** Session name; defaults to LITEBACKUP_SESSION, then "default". */
|
|
13
|
+
session?: string;
|
|
14
|
+
/** Environment for resolving paths and starting the daemon; defaults to process.env. */
|
|
15
|
+
environment?: NodeJS.ProcessEnv;
|
|
16
|
+
/** Start the session daemon when it is not running; defaults to true. */
|
|
17
|
+
launch?: boolean;
|
|
18
|
+
/** Connect to this socket and never start a daemon. */
|
|
19
|
+
socketPath?: string;
|
|
20
|
+
}
|
|
21
|
+
/** Options for acquire. */
|
|
22
|
+
export interface AcquireOptions {
|
|
23
|
+
/** Local file; relative paths resolve against the working directory. Defaults to the path this machine uses, which brings an offloaded database back. */
|
|
24
|
+
to?: string;
|
|
25
|
+
/** Checkpoint on release and VACUUM past the freelist threshold. */
|
|
26
|
+
maintenance?: boolean;
|
|
27
|
+
/** "released" lets Litebackup remove the released copy once the bucket holds it. */
|
|
28
|
+
offload?: "never" | "released";
|
|
29
|
+
/** What other machines see as the writer. */
|
|
30
|
+
machineLabel?: string;
|
|
31
|
+
/** On a lost write lock, keep the copy as conflicted (default) or block local writes until the lock is back. */
|
|
32
|
+
onLost?: "conflict" | "block";
|
|
33
|
+
/** Bound on downloading the head. */
|
|
34
|
+
timeout?: Duration;
|
|
35
|
+
}
|
|
36
|
+
/** Options for release. */
|
|
37
|
+
export interface ReleaseOptions {
|
|
38
|
+
/** server returns once the final sync is acknowledged; cloud waits for the bucket too. */
|
|
39
|
+
wait?: Durability;
|
|
40
|
+
/** Remove the local file once the bucket holds the released version. */
|
|
41
|
+
offload?: boolean;
|
|
42
|
+
/** How long to wait for the database to close and for the chosen durability. */
|
|
43
|
+
timeout?: Duration;
|
|
44
|
+
}
|
|
45
|
+
/** Options for replicate. */
|
|
46
|
+
export interface ReplicateOptions {
|
|
47
|
+
/** Replica file; relative paths resolve against the working directory. Defaults to the path this machine uses. */
|
|
48
|
+
to?: string;
|
|
49
|
+
/** lock (default) makes app writes fail with SQLITE_BUSY; detect rebases after a local write; none trusts apps to open with mode=ro. */
|
|
50
|
+
writeProtection?: WriteProtection;
|
|
51
|
+
/** Bound on downloading the first version. */
|
|
52
|
+
timeout?: Duration;
|
|
53
|
+
}
|
|
54
|
+
/** Options for restore: a version, a time, or neither for the head. */
|
|
55
|
+
export interface RestoreOptions {
|
|
56
|
+
/** The new file; relative paths resolve against the working directory. Its directory must exist and the file must not. */
|
|
57
|
+
to: string;
|
|
58
|
+
version?: number;
|
|
59
|
+
/** Restore the newest version at or before this time. */
|
|
60
|
+
time?: Date | string;
|
|
61
|
+
}
|
|
62
|
+
/** Options for versions. */
|
|
63
|
+
export interface VersionsOptions {
|
|
64
|
+
/** Skip versions up to and including this one. */
|
|
65
|
+
after?: number;
|
|
66
|
+
/** Return at most this many; every version when unset. */
|
|
67
|
+
limit?: number;
|
|
68
|
+
}
|
|
69
|
+
/** Options for events. */
|
|
70
|
+
export interface EventsOptions {
|
|
71
|
+
/** Return events with IDs greater than this one; 0 starts at the oldest. */
|
|
72
|
+
after?: number;
|
|
73
|
+
/** How long each long-poll waits for a new event; defaults to 30s. */
|
|
74
|
+
wait?: Duration;
|
|
75
|
+
signal?: AbortSignal;
|
|
76
|
+
}
|
|
77
|
+
/** Options for shutdown. */
|
|
78
|
+
export interface ShutdownOptions {
|
|
79
|
+
wait?: "none" | Durability;
|
|
80
|
+
timeout?: Duration;
|
|
81
|
+
}
|
|
82
|
+
/** Names a backup or failover to stop by one of its ID, a database name, or its path. */
|
|
83
|
+
export type StopBackupTarget = {
|
|
84
|
+
id: string;
|
|
85
|
+
} | {
|
|
86
|
+
name: string;
|
|
87
|
+
} | {
|
|
88
|
+
path: string;
|
|
89
|
+
};
|
|
90
|
+
/** Resolves a path against the working directory; the daemon needs absolute paths. */
|
|
91
|
+
export declare function absolutePath(path: string): string;
|
|
92
|
+
/** Talks to the Litebackup daemon of one session over its unix socket. */
|
|
93
|
+
export declare class Litebackup {
|
|
94
|
+
readonly session: string;
|
|
95
|
+
readonly socketPath: string;
|
|
96
|
+
/** The daemon's version, known after the first call. */
|
|
97
|
+
clientVersion: string;
|
|
98
|
+
/** Backups and failovers running on this machine. */
|
|
99
|
+
readonly backups: {
|
|
100
|
+
list(): Promise<BackupInfo[]>;
|
|
101
|
+
stop(target: StopBackupTarget): Promise<void>;
|
|
102
|
+
};
|
|
103
|
+
/** Prefix replicas and replicas on this machine. */
|
|
104
|
+
readonly replicas: {
|
|
105
|
+
list(): Promise<ReplicaList>;
|
|
106
|
+
stop(name: string): Promise<void>;
|
|
107
|
+
};
|
|
108
|
+
/** Conflict copies, saved because they diverged from the server: list and delete. */
|
|
109
|
+
readonly conflicts: {
|
|
110
|
+
list(): Promise<Conflict[]>;
|
|
111
|
+
delete(id: string): Promise<void>;
|
|
112
|
+
};
|
|
113
|
+
/** @internal */
|
|
114
|
+
/** Failovers this client follows; close() stops following them. @internal */
|
|
115
|
+
readonly failovers: Set<Failover>;
|
|
116
|
+
/** @internal */
|
|
117
|
+
closed: boolean;
|
|
118
|
+
/** Use Litebackup.connect, which starts the daemon when needed. */
|
|
119
|
+
private constructor();
|
|
120
|
+
/** Connects to a session, starting its daemon like the CLI does. */
|
|
121
|
+
static connect(options?: ConnectOptions): Promise<Litebackup>;
|
|
122
|
+
/**
|
|
123
|
+
* Sends one call and decodes its JSON answer into camelCase, throwing
|
|
124
|
+
* LitebackupError on failure.
|
|
125
|
+
* @internal
|
|
126
|
+
*/
|
|
127
|
+
call<T>(method: "GET" | "POST", path: string, body?: unknown, signal?: AbortSignal): Promise<any>;
|
|
128
|
+
/**
|
|
129
|
+
* Backs up a database, given as a path or a better-sqlite3 handle, and
|
|
130
|
+
* keeps syncing it. Returns at once; see Backup for how failures surface.
|
|
131
|
+
*/
|
|
132
|
+
backup(source: BackupSource, options?: BackupOptions): Backup;
|
|
133
|
+
/**
|
|
134
|
+
* Runs a database on several identical machines: the first to take the
|
|
135
|
+
* write lock is the origin, the others keep live read-only replicas at the
|
|
136
|
+
* same path and take over when the origin's lease runs out.
|
|
137
|
+
*/
|
|
138
|
+
failover(path: string, options?: FailoverOptions): Promise<Failover>;
|
|
139
|
+
/** Keeps a live read-only replica of a database and resolves once its first version is local. */
|
|
140
|
+
replicate(name: string, options?: ReplicateOptions): Promise<DatabaseStatus>;
|
|
141
|
+
/** Writes a version of a database to a new file and checks it. An existing file is never overwritten (exists). */
|
|
142
|
+
restore(name: string, options: RestoreOptions): Promise<RestoreResult>;
|
|
143
|
+
/** The versions of a database the server can restore, oldest first. */
|
|
144
|
+
versions(name: string, options?: VersionsOptions): Promise<Version[]>;
|
|
145
|
+
/** Takes the write lock on a database and makes the local file the server head, for worker pools that move databases between machines. */
|
|
146
|
+
acquire(name: string, options?: AcquireOptions): Promise<AcquireResult>;
|
|
147
|
+
/** Syncs an acquired database a final time, runs its maintenance, and releases its write lock. */
|
|
148
|
+
release(name: string, options?: ReleaseOptions): Promise<ReleaseResult>;
|
|
149
|
+
/** Which machine writes a database, when its lease runs out, and whether it ran out. */
|
|
150
|
+
writer(name: string): Promise<Writer>;
|
|
151
|
+
/** The session, its server, and every database on this machine. */
|
|
152
|
+
status(): Promise<Status>;
|
|
153
|
+
/** Every database on this machine with its role and state. */
|
|
154
|
+
databases(): Promise<DatabaseStatus[]>;
|
|
155
|
+
/** One database: its role, state, and the versions the server and the bucket hold. */
|
|
156
|
+
database(name: string): Promise<DatabaseStatus>;
|
|
157
|
+
/** Syncs a database now and resolves once the server acknowledged it. */
|
|
158
|
+
sync(name: string): Promise<DatabaseStatus>;
|
|
159
|
+
/** Removes the local file of a released database once the bucket holds its last version; acquire brings it back. */
|
|
160
|
+
offload(name: string): Promise<DatabaseStatus>;
|
|
161
|
+
/** One page of events after an ID, waiting up to waitMillis for the first. */
|
|
162
|
+
eventPage(options?: {
|
|
163
|
+
after?: number;
|
|
164
|
+
waitMillis?: number;
|
|
165
|
+
limit?: number;
|
|
166
|
+
signal?: AbortSignal;
|
|
167
|
+
}): Promise<EventList>;
|
|
168
|
+
/** Yields events, oldest first, by long-polling the daemon until the signal aborts. */
|
|
169
|
+
events(options?: EventsOptions): AsyncGenerator<LitebackupEvent>;
|
|
170
|
+
/** Syncs every database a final time, releases every write lock, ends the session, and stops the daemon. */
|
|
171
|
+
shutdown(options?: ShutdownOptions): Promise<ShutdownResult>;
|
|
172
|
+
/** Stops watching failovers. The daemon keeps running. */
|
|
173
|
+
close(): void;
|
|
174
|
+
}
|