@litebackup/sdk 0.3.29 → 0.3.31
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.js +5 -3
- package/dist/src/client.d.ts +19 -4
- package/dist/src/client.js +26 -5
- package/dist/src/helpers.d.ts +4 -2
- package/dist/src/helpers.js +4 -0
- package/dist/src/index.d.ts +2 -2
- package/dist/src/index.js +1 -1
- package/dist/src/release.js +2 -2
- package/dist/src/types.d.ts +1 -1
- package/dist/src/types.js +1 -1
- package/package.json +5 -5
package/dist/src/backup.js
CHANGED
|
@@ -106,19 +106,21 @@ export class Backup {
|
|
|
106
106
|
if (durability !== "server" && durability !== "cloud") {
|
|
107
107
|
throw new LitebackupError("invalid_argument", `wait for server or cloud, not ${JSON.stringify(durability)}`, 0);
|
|
108
108
|
}
|
|
109
|
+
options.signal?.throwIfAborted();
|
|
109
110
|
const started = await this.ready;
|
|
111
|
+
options.signal?.throwIfAborted();
|
|
110
112
|
const litebackup = await this.client;
|
|
111
|
-
const listed = (await litebackup.backups.list()).find((backup) => backup.id === started.id);
|
|
113
|
+
const listed = (await litebackup.backups.list(options)).find((backup) => backup.id === started.id);
|
|
112
114
|
const names = (listed ?? started).databases.map((database) => database.name);
|
|
113
115
|
if (names.length === 0 && this.name) {
|
|
114
116
|
names.push(this.name);
|
|
115
117
|
}
|
|
116
118
|
for (const name of names) {
|
|
117
|
-
const synced = await litebackup.sync(name);
|
|
119
|
+
const synced = await litebackup.sync(name, options);
|
|
118
120
|
if (durability === "cloud") {
|
|
119
121
|
for (;;) {
|
|
120
122
|
options.signal?.throwIfAborted();
|
|
121
|
-
const status = await litebackup.database(name);
|
|
123
|
+
const status = await litebackup.database(name, options);
|
|
122
124
|
if (status.syncedCloud.version >= synced.syncedServer.version) {
|
|
123
125
|
break;
|
|
124
126
|
}
|
package/dist/src/client.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Backup, type BackupOptions, type BackupSource } from "./backup.js";
|
|
2
2
|
import { type Duration } from "./duration.js";
|
|
3
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";
|
|
4
|
+
import { type AcquireResult, type BackupInfo, type Conflict, type DatabaseStatus, type Durability, type EventList, type LitebackupEvent, type PrefixReplica, type ReleaseResult, type ReplicaList, type RestoreResult, type ShutdownResult, type Status, type Version, type WriteProtection, type Writer } from "./types.js";
|
|
5
5
|
/** Options for connecting to a Litebackup session. */
|
|
6
6
|
export interface ConnectOptions {
|
|
7
7
|
/**
|
|
@@ -51,6 +51,12 @@ export interface ReplicateOptions {
|
|
|
51
51
|
/** Bound on downloading the first version. */
|
|
52
52
|
timeout?: Duration;
|
|
53
53
|
}
|
|
54
|
+
/** Options for replicating a namespace; registration does not wait for downloads. */
|
|
55
|
+
export interface ReplicatePrefixOptions {
|
|
56
|
+
/** Directory receiving each database at its name relative to the prefix. */
|
|
57
|
+
to: string;
|
|
58
|
+
writeProtection?: WriteProtection;
|
|
59
|
+
}
|
|
54
60
|
/** Options for restore: a version, a time, or neither for the head. */
|
|
55
61
|
export interface RestoreOptions {
|
|
56
62
|
/** The new file; relative paths resolve against the working directory. Its directory must exist and the file must not. */
|
|
@@ -97,13 +103,16 @@ export declare class Litebackup {
|
|
|
97
103
|
clientVersion: string;
|
|
98
104
|
/** Backups and failovers running on this machine. */
|
|
99
105
|
readonly backups: {
|
|
100
|
-
list(
|
|
106
|
+
list(options?: {
|
|
107
|
+
signal?: AbortSignal;
|
|
108
|
+
}): Promise<BackupInfo[]>;
|
|
101
109
|
stop(target: StopBackupTarget): Promise<void>;
|
|
102
110
|
};
|
|
103
111
|
/** Prefix replicas and replicas on this machine. */
|
|
104
112
|
readonly replicas: {
|
|
105
113
|
list(): Promise<ReplicaList>;
|
|
106
114
|
stop(name: string): Promise<void>;
|
|
115
|
+
stopPrefix(prefix: string, to: string): Promise<void>;
|
|
107
116
|
};
|
|
108
117
|
/** Conflict copies, saved because they diverged from the server: list and delete. */
|
|
109
118
|
readonly conflicts: {
|
|
@@ -138,6 +147,8 @@ export declare class Litebackup {
|
|
|
138
147
|
failover(path: string, options?: FailoverOptions): Promise<Failover>;
|
|
139
148
|
/** Keeps a live readonly replica of a database and resolves once its first version is local. */
|
|
140
149
|
replicate(name: string, options?: ReplicateOptions): Promise<DatabaseStatus>;
|
|
150
|
+
/** Registers live readonly replicas of current and future databases under a prefix. An empty prefix follows all databases. */
|
|
151
|
+
replicatePrefix(prefix: string, options: ReplicatePrefixOptions): Promise<PrefixReplica>;
|
|
141
152
|
/** Writes a version of a database to a new file and checks it. An existing file is never overwritten (exists). */
|
|
142
153
|
restore(name: string, options: RestoreOptions): Promise<RestoreResult>;
|
|
143
154
|
/** The versions of a database the server can restore, oldest first. */
|
|
@@ -153,9 +164,13 @@ export declare class Litebackup {
|
|
|
153
164
|
/** Every database on this machine with its role and state. */
|
|
154
165
|
databases(): Promise<DatabaseStatus[]>;
|
|
155
166
|
/** One database: its role, state, and the versions the server and the bucket hold. */
|
|
156
|
-
database(name: string
|
|
167
|
+
database(name: string, options?: {
|
|
168
|
+
signal?: AbortSignal;
|
|
169
|
+
}): Promise<DatabaseStatus>;
|
|
157
170
|
/** Syncs a database now and resolves once the server acknowledged it. */
|
|
158
|
-
sync(name: string
|
|
171
|
+
sync(name: string, options?: {
|
|
172
|
+
signal?: AbortSignal;
|
|
173
|
+
}): Promise<DatabaseStatus>;
|
|
159
174
|
/** Removes the local file of a released database once the bucket holds its last version; acquire brings it back. */
|
|
160
175
|
offload(name: string): Promise<DatabaseStatus>;
|
|
161
176
|
/** One page of events after an ID, waiting up to waitMillis for the first. */
|
package/dist/src/client.js
CHANGED
|
@@ -36,7 +36,7 @@ export class Litebackup {
|
|
|
36
36
|
this.session = session;
|
|
37
37
|
this.socketPath = socketPath;
|
|
38
38
|
this.backups = {
|
|
39
|
-
list: async () => (await this.call("GET", "/v1/backups/list")).backups,
|
|
39
|
+
list: async (options = {}) => (await this.call("GET", "/v1/backups/list", undefined, options.signal)).backups,
|
|
40
40
|
stop: async (target) => {
|
|
41
41
|
const body = "path" in target ? { path: absolutePath(target.path) } : target;
|
|
42
42
|
await this.call("POST", "/v1/backups/stop", body);
|
|
@@ -44,6 +44,12 @@ export class Litebackup {
|
|
|
44
44
|
};
|
|
45
45
|
this.replicas = {
|
|
46
46
|
list: () => this.call("GET", "/v1/replicas/list"),
|
|
47
|
+
stopPrefix: async (prefix, to) => {
|
|
48
|
+
if (!to) {
|
|
49
|
+
throw new LitebackupError("invalid_argument", "stopping a prefix replica needs a directory", 0);
|
|
50
|
+
}
|
|
51
|
+
await this.call("POST", "/v1/replicas/stop", { prefix, to: absolutePath(to) });
|
|
52
|
+
},
|
|
47
53
|
stop: async (name) => {
|
|
48
54
|
await this.call("POST", "/v1/replicas/stop", { name });
|
|
49
55
|
},
|
|
@@ -135,6 +141,21 @@ export class Litebackup {
|
|
|
135
141
|
}
|
|
136
142
|
return result.database;
|
|
137
143
|
}
|
|
144
|
+
/** Registers live readonly replicas of current and future databases under a prefix. An empty prefix follows all databases. */
|
|
145
|
+
async replicatePrefix(prefix, options) {
|
|
146
|
+
if (!options?.to) {
|
|
147
|
+
throw new LitebackupError("invalid_argument", "replicating a prefix needs a directory", 0);
|
|
148
|
+
}
|
|
149
|
+
const body = { prefix, to: absolutePath(options.to) };
|
|
150
|
+
if (options.writeProtection) {
|
|
151
|
+
body.write_protection = options.writeProtection;
|
|
152
|
+
}
|
|
153
|
+
const result = (await this.call("POST", "/v1/replicas/start", body));
|
|
154
|
+
if (!result.prefix) {
|
|
155
|
+
throw new LitebackupError("invalid_response", "the daemon did not return the prefix replica", 200);
|
|
156
|
+
}
|
|
157
|
+
return result.prefix;
|
|
158
|
+
}
|
|
138
159
|
/** Writes a version of a database to a new file and checks it. An existing file is never overwritten (exists). */
|
|
139
160
|
restore(name, options) {
|
|
140
161
|
if (!options?.to) {
|
|
@@ -223,12 +244,12 @@ export class Litebackup {
|
|
|
223
244
|
return (await this.call("GET", "/v1/databases/list")).databases;
|
|
224
245
|
}
|
|
225
246
|
/** One database: its role, state, and the versions the server and the bucket hold. */
|
|
226
|
-
database(name) {
|
|
227
|
-
return this.call("GET", `/v1/databases/status?${new URLSearchParams({ name })}
|
|
247
|
+
database(name, options = {}) {
|
|
248
|
+
return this.call("GET", `/v1/databases/status?${new URLSearchParams({ name })}`, undefined, options.signal);
|
|
228
249
|
}
|
|
229
250
|
/** Syncs a database now and resolves once the server acknowledged it. */
|
|
230
|
-
sync(name) {
|
|
231
|
-
return this.call("POST", "/v1/databases/sync", { name });
|
|
251
|
+
sync(name, options = {}) {
|
|
252
|
+
return this.call("POST", "/v1/databases/sync", { name }, options.signal);
|
|
232
253
|
}
|
|
233
254
|
/** Removes the local file of a released database once the bucket holds its last version; acquire brings it back. */
|
|
234
255
|
offload(name) {
|
package/dist/src/helpers.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Backup, type BackupOptions, type BackupSource } from "./backup.js";
|
|
2
|
-
import { Litebackup, type AcquireOptions, type ReleaseOptions, type ReplicateOptions, type RestoreOptions, type VersionsOptions } from "./client.js";
|
|
2
|
+
import { Litebackup, type AcquireOptions, type ReleaseOptions, type ReplicateOptions, type ReplicatePrefixOptions, type RestoreOptions, type VersionsOptions } from "./client.js";
|
|
3
3
|
import type { Failover, FailoverOptions } from "./failover.js";
|
|
4
|
-
import type { AcquireResult, DatabaseStatus, ReleaseResult, RestoreResult, Version, Writer } from "./types.js";
|
|
4
|
+
import type { AcquireResult, DatabaseStatus, PrefixReplica, ReleaseResult, RestoreResult, Version, Writer } from "./types.js";
|
|
5
5
|
/** Picks the shared client of the helpers. */
|
|
6
6
|
export interface SharedClientOptions {
|
|
7
7
|
/** Join token; defaults to LITEBACKUP_TOKEN. */
|
|
@@ -24,6 +24,8 @@ export declare function backup(source: BackupSource, options?: BackupOptions): B
|
|
|
24
24
|
export declare function failover(path: string, options?: FailoverOptions): Promise<Failover>;
|
|
25
25
|
/** Keeps a live readonly replica of a database; resolves once its first version is local. */
|
|
26
26
|
export declare function replicate(name: string, options?: ReplicateOptions & SharedClientOptions): Promise<DatabaseStatus>;
|
|
27
|
+
/** Registers live replicas of a namespace; downloads happen in the background. */
|
|
28
|
+
export declare function replicatePrefix(prefix: string, options: ReplicatePrefixOptions & SharedClientOptions): Promise<PrefixReplica>;
|
|
27
29
|
/** Writes a version of a database to a new file and checks it. */
|
|
28
30
|
export declare function restore(name: string, options: RestoreOptions & SharedClientOptions): Promise<RestoreResult>;
|
|
29
31
|
/** The versions of a database the server can restore, oldest first. */
|
package/dist/src/helpers.js
CHANGED
|
@@ -49,6 +49,10 @@ export async function failover(path, options = {}) {
|
|
|
49
49
|
export async function replicate(name, options = {}) {
|
|
50
50
|
return (await sharedClient(options)).replicate(name, options);
|
|
51
51
|
}
|
|
52
|
+
/** Registers live replicas of a namespace; downloads happen in the background. */
|
|
53
|
+
export async function replicatePrefix(prefix, options) {
|
|
54
|
+
return (await sharedClient(options)).replicatePrefix(prefix, withoutClientOptions(options));
|
|
55
|
+
}
|
|
52
56
|
/** Writes a version of a database to a new file and checks it. */
|
|
53
57
|
export async function restore(name, options) {
|
|
54
58
|
return (await sharedClient(options)).restore(name, options);
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { acquire, backup, failover, offload, release, replicate, restore, versions, writer, sharedClient } from "./helpers.js";
|
|
1
|
+
export { acquire, backup, failover, offload, release, replicate, replicatePrefix, restore, versions, writer, sharedClient } from "./helpers.js";
|
|
2
2
|
export type { SharedClientOptions } from "./helpers.js";
|
|
3
3
|
export { Litebackup } from "./client.js";
|
|
4
|
-
export type { AcquireOptions, ConnectOptions, EventsOptions, ReleaseOptions, ReplicateOptions, RestoreOptions, ShutdownOptions, StopBackupTarget, VersionsOptions, } from "./client.js";
|
|
4
|
+
export type { AcquireOptions, ConnectOptions, EventsOptions, ReleaseOptions, ReplicateOptions, ReplicatePrefixOptions, RestoreOptions, ShutdownOptions, StopBackupTarget, VersionsOptions, } from "./client.js";
|
|
5
5
|
export { Backup } from "./backup.js";
|
|
6
6
|
export type { BackupOptions, BackupSource, SQLiteHandle } from "./backup.js";
|
|
7
7
|
export { Failover } from "./failover.js";
|
package/dist/src/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { acquire, backup, failover, offload, release, replicate, restore, versions, writer, sharedClient } from "./helpers.js";
|
|
1
|
+
export { acquire, backup, failover, offload, release, replicate, replicatePrefix, restore, versions, writer, sharedClient } from "./helpers.js";
|
|
2
2
|
export { Litebackup } from "./client.js";
|
|
3
3
|
export { Backup } from "./backup.js";
|
|
4
4
|
export { Failover } from "./failover.js";
|
package/dist/src/release.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { createPublicKey, verify } from "node:crypto";
|
|
2
2
|
/** Litebackup's Ed25519 release keys by key ID, base64url without padding, as the litebackup command checks them. */
|
|
3
3
|
export const releaseKeys = {
|
|
4
|
-
"
|
|
4
|
+
"01a1ead6-4b94-79ca-81f4-3a67c112bc0b": "t3C_3l71PimyhkPZOzJ_Xi4dOuHJ1CmSdDZ8lTm0vNI",
|
|
5
5
|
};
|
|
6
|
-
/** Frames
|
|
6
|
+
/** Frames signed release metadata: context, key ID, separator, document. */
|
|
7
7
|
const signatureContext = "clor-apps-v1\u0000";
|
|
8
8
|
const signatureSeparator = "\u0000";
|
|
9
9
|
/** A release whose signature does not match Litebackup's release keys. */
|
package/dist/src/types.d.ts
CHANGED
|
@@ -28,7 +28,7 @@ export type LitebackupEvent = Camelize<Schemas["Event"]>;
|
|
|
28
28
|
export type EventList = Camelize<Schemas["EventList"]>;
|
|
29
29
|
export type ShutdownResult = Camelize<Schemas["ShutdownResult"]>;
|
|
30
30
|
/** The SDK version sent with every call. */
|
|
31
|
-
export declare const sdkVersion = "0.3.
|
|
31
|
+
export declare const sdkVersion = "0.3.31";
|
|
32
32
|
/** An error the Litebackup daemon answered with, carrying its code. */
|
|
33
33
|
export declare class LitebackupError extends Error {
|
|
34
34
|
/** Such as name_in_use, exists, in_use, not_found, still_open, timeout, or sdk_unsupported. */
|
package/dist/src/types.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** The SDK version sent with every call. */
|
|
2
|
-
export const sdkVersion = "0.3.
|
|
2
|
+
export const sdkVersion = "0.3.31";
|
|
3
3
|
/** An error the Litebackup daemon answered with, carrying its code. */
|
|
4
4
|
export class LitebackupError extends Error {
|
|
5
5
|
/** Such as name_in_use, exists, in_use, not_found, still_open, timeout, or sdk_unsupported. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@litebackup/sdk",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.31",
|
|
4
4
|
"description": "Back up, replicate, and restore SQLite databases with Litebackup",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"type": "module",
|
|
@@ -25,10 +25,10 @@
|
|
|
25
25
|
"prepack": "npm run build"
|
|
26
26
|
},
|
|
27
27
|
"optionalDependencies": {
|
|
28
|
-
"@litebackup/bin-darwin-arm64": "0.3.
|
|
29
|
-
"@litebackup/bin-darwin-x64": "0.3.
|
|
30
|
-
"@litebackup/bin-linux-arm64": "0.3.
|
|
31
|
-
"@litebackup/bin-linux-x64": "0.3.
|
|
28
|
+
"@litebackup/bin-darwin-arm64": "0.3.31",
|
|
29
|
+
"@litebackup/bin-darwin-x64": "0.3.31",
|
|
30
|
+
"@litebackup/bin-linux-arm64": "0.3.31",
|
|
31
|
+
"@litebackup/bin-linux-x64": "0.3.31"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@types/node": "24.19.2",
|