@sixfathoms/lplex 0.1.0 → 0.2.0
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/README.md +30 -0
- package/dist/index.cjs +66 -0
- package/dist/index.d.cts +83 -5
- package/dist/index.d.ts +83 -5
- package/dist/index.js +65 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -58,6 +58,20 @@ for (const d of devices) {
|
|
|
58
58
|
}
|
|
59
59
|
```
|
|
60
60
|
|
|
61
|
+
### `client.values(signal?): Promise<DeviceValues[]>`
|
|
62
|
+
|
|
63
|
+
Returns the last-seen value for each (device, PGN) pair, grouped by device. Useful for getting a snapshot of current bus state without subscribing to SSE.
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
const snapshot = await client.values();
|
|
67
|
+
for (const device of snapshot) {
|
|
68
|
+
console.log(`${device.manufacturer} (src=${device.src}):`);
|
|
69
|
+
for (const v of device.values) {
|
|
70
|
+
console.log(` PGN ${v.pgn}: ${v.data} @ ${v.ts}`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
61
75
|
### `client.subscribe(filter?, signal?): Promise<AsyncIterable<Event>>`
|
|
62
76
|
|
|
63
77
|
Opens an ephemeral SSE stream. No session state, no replay. Frames flow until you stop reading or abort.
|
|
@@ -285,6 +299,21 @@ interface SendParams {
|
|
|
285
299
|
prio: number;
|
|
286
300
|
data: string; // hex-encoded
|
|
287
301
|
}
|
|
302
|
+
|
|
303
|
+
interface PGNValue {
|
|
304
|
+
pgn: number;
|
|
305
|
+
ts: string; // RFC 3339 timestamp
|
|
306
|
+
data: string; // hex-encoded payload
|
|
307
|
+
seq: number; // sequence number
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
interface DeviceValues {
|
|
311
|
+
name: string; // hex CAN NAME (empty if unknown)
|
|
312
|
+
src: number; // source address
|
|
313
|
+
manufacturer?: string;
|
|
314
|
+
model_id?: string;
|
|
315
|
+
values: PGNValue[]; // sorted by PGN
|
|
316
|
+
}
|
|
288
317
|
```
|
|
289
318
|
|
|
290
319
|
## Server Endpoints
|
|
@@ -297,6 +326,7 @@ interface SendParams {
|
|
|
297
326
|
| `/clients/{id}/ack` | PUT | ACK sequence number. JSON body: `{ "seq": N }`. Returns 204. |
|
|
298
327
|
| `/send` | POST | Transmit CAN frame. JSON body: `pgn`, `src`, `dst`, `prio`, `data`. Returns 202. |
|
|
299
328
|
| `/devices` | GET | Device snapshot. Returns JSON array. |
|
|
329
|
+
| `/values` | GET | Last-seen value per (device, PGN). Returns JSON array grouped by device. |
|
|
300
330
|
|
|
301
331
|
## License
|
|
302
332
|
|
package/dist/index.cjs
CHANGED
|
@@ -21,6 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
Client: () => Client,
|
|
24
|
+
CloudClient: () => CloudClient,
|
|
24
25
|
HttpError: () => HttpError,
|
|
25
26
|
LplexError: () => LplexError,
|
|
26
27
|
Session: () => Session
|
|
@@ -169,6 +170,16 @@ var Client = class {
|
|
|
169
170
|
}
|
|
170
171
|
return resp.json();
|
|
171
172
|
}
|
|
173
|
+
/** Fetch the last-seen value for each (device, PGN) pair. */
|
|
174
|
+
async values(signal) {
|
|
175
|
+
const url = `${this.#baseURL}/values`;
|
|
176
|
+
const resp = await this.#fetch(url, { signal });
|
|
177
|
+
if (!resp.ok) {
|
|
178
|
+
const body = await resp.text();
|
|
179
|
+
throw new HttpError("GET", url, resp.status, body);
|
|
180
|
+
}
|
|
181
|
+
return resp.json();
|
|
182
|
+
}
|
|
172
183
|
/**
|
|
173
184
|
* Open an ephemeral SSE stream with optional filtering.
|
|
174
185
|
* No session, no replay, no ACK.
|
|
@@ -247,9 +258,64 @@ function filterToJSON(f) {
|
|
|
247
258
|
if (f.name?.length) m.name = f.name;
|
|
248
259
|
return m;
|
|
249
260
|
}
|
|
261
|
+
|
|
262
|
+
// src/cloud.ts
|
|
263
|
+
var CloudClient = class {
|
|
264
|
+
#baseURL;
|
|
265
|
+
#fetch;
|
|
266
|
+
#fetchOpt;
|
|
267
|
+
constructor(baseURL, options) {
|
|
268
|
+
this.#baseURL = baseURL.replace(/\/+$/, "");
|
|
269
|
+
this.#fetch = options?.fetch ?? globalThis.fetch.bind(globalThis);
|
|
270
|
+
this.#fetchOpt = options ?? {};
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Returns a {@link Client} scoped to a specific instance.
|
|
274
|
+
* The returned client's `devices()`, `subscribe()`, etc. hit the
|
|
275
|
+
* cloud's per-instance endpoints.
|
|
276
|
+
*/
|
|
277
|
+
client(instanceId) {
|
|
278
|
+
const opts = {};
|
|
279
|
+
if (this.#fetchOpt.fetch) opts.fetch = this.#fetchOpt.fetch;
|
|
280
|
+
return new Client(`${this.#baseURL}/instances/${instanceId}`, opts);
|
|
281
|
+
}
|
|
282
|
+
/** List all known instances. */
|
|
283
|
+
async instances(signal) {
|
|
284
|
+
const url = `${this.#baseURL}/instances`;
|
|
285
|
+
const resp = await this.#fetch(url, { signal });
|
|
286
|
+
if (!resp.ok) {
|
|
287
|
+
const body = await resp.text();
|
|
288
|
+
throw new HttpError("GET", url, resp.status, body);
|
|
289
|
+
}
|
|
290
|
+
const data = await resp.json();
|
|
291
|
+
return data.instances;
|
|
292
|
+
}
|
|
293
|
+
/** Get detailed replication status for one instance. */
|
|
294
|
+
async status(instanceId, signal) {
|
|
295
|
+
const url = `${this.#baseURL}/instances/${instanceId}/status`;
|
|
296
|
+
const resp = await this.#fetch(url, { signal });
|
|
297
|
+
if (!resp.ok) {
|
|
298
|
+
const body = await resp.text();
|
|
299
|
+
throw new HttpError("GET", url, resp.status, body);
|
|
300
|
+
}
|
|
301
|
+
return resp.json();
|
|
302
|
+
}
|
|
303
|
+
/** Fetch recent replication diagnostic events for an instance. */
|
|
304
|
+
async replicationEvents(instanceId, limit, signal) {
|
|
305
|
+
let url = `${this.#baseURL}/instances/${instanceId}/replication/events`;
|
|
306
|
+
if (limit !== void 0) url += `?limit=${limit}`;
|
|
307
|
+
const resp = await this.#fetch(url, { signal });
|
|
308
|
+
if (!resp.ok) {
|
|
309
|
+
const body = await resp.text();
|
|
310
|
+
throw new HttpError("GET", url, resp.status, body);
|
|
311
|
+
}
|
|
312
|
+
return resp.json();
|
|
313
|
+
}
|
|
314
|
+
};
|
|
250
315
|
// Annotate the CommonJS export names for ESM import in node:
|
|
251
316
|
0 && (module.exports = {
|
|
252
317
|
Client,
|
|
318
|
+
CloudClient,
|
|
253
319
|
HttpError,
|
|
254
320
|
LplexError,
|
|
255
321
|
Session
|
package/dist/index.d.cts
CHANGED
|
@@ -67,12 +67,61 @@ interface SendParams {
|
|
|
67
67
|
prio: number;
|
|
68
68
|
data: string;
|
|
69
69
|
}
|
|
70
|
+
/** A single PGN's last-known value for a device. */
|
|
71
|
+
interface PGNValue {
|
|
72
|
+
pgn: number;
|
|
73
|
+
ts: string;
|
|
74
|
+
data: string;
|
|
75
|
+
seq: number;
|
|
76
|
+
}
|
|
77
|
+
/** Last-known values grouped by device. */
|
|
78
|
+
interface DeviceValues {
|
|
79
|
+
name: string;
|
|
80
|
+
src: number;
|
|
81
|
+
manufacturer?: string;
|
|
82
|
+
model_id?: string;
|
|
83
|
+
values: PGNValue[];
|
|
84
|
+
}
|
|
85
|
+
/** Summary of a cloud instance, returned by GET /instances. */
|
|
86
|
+
interface InstanceSummary {
|
|
87
|
+
id: string;
|
|
88
|
+
connected: boolean;
|
|
89
|
+
cursor: number;
|
|
90
|
+
boat_head_seq: number;
|
|
91
|
+
holes: number;
|
|
92
|
+
lag_seqs: number;
|
|
93
|
+
last_seen: string;
|
|
94
|
+
}
|
|
95
|
+
/** A sequence range representing a gap in the replication stream. */
|
|
96
|
+
interface SeqRange {
|
|
97
|
+
start: number;
|
|
98
|
+
end: number;
|
|
99
|
+
}
|
|
100
|
+
/** Detailed replication status for one instance. */
|
|
101
|
+
interface InstanceStatus {
|
|
102
|
+
id: string;
|
|
103
|
+
connected: boolean;
|
|
104
|
+
cursor: number;
|
|
105
|
+
boat_head_seq: number;
|
|
106
|
+
boat_journal_bytes: number;
|
|
107
|
+
holes: SeqRange[];
|
|
108
|
+
lag_seqs: number;
|
|
109
|
+
last_seen: string;
|
|
110
|
+
}
|
|
111
|
+
/** Event types emitted by the replication pipeline. */
|
|
112
|
+
type ReplicationEventType = "live_start" | "live_stop" | "backfill_start" | "backfill_stop" | "block_received" | "checkpoint";
|
|
113
|
+
/** A single diagnostic event from the replication pipeline. */
|
|
114
|
+
interface ReplicationEvent {
|
|
115
|
+
time: string;
|
|
116
|
+
type: ReplicationEventType;
|
|
117
|
+
detail?: Record<string, unknown>;
|
|
118
|
+
}
|
|
70
119
|
|
|
71
|
-
type FetchFn$
|
|
120
|
+
type FetchFn$2 = typeof globalThis.fetch;
|
|
72
121
|
declare class Session {
|
|
73
122
|
#private;
|
|
74
123
|
/** @internal Created by Client.createSession, not for direct use. */
|
|
75
|
-
constructor(baseURL: string, fetchFn: FetchFn$
|
|
124
|
+
constructor(baseURL: string, fetchFn: FetchFn$2, info: SessionInfo);
|
|
76
125
|
get info(): SessionInfo;
|
|
77
126
|
get lastAckedSeq(): number;
|
|
78
127
|
/**
|
|
@@ -84,15 +133,17 @@ declare class Session {
|
|
|
84
133
|
ack(seq: number, signal?: AbortSignal): Promise<void>;
|
|
85
134
|
}
|
|
86
135
|
|
|
87
|
-
type FetchFn = typeof globalThis.fetch;
|
|
136
|
+
type FetchFn$1 = typeof globalThis.fetch;
|
|
88
137
|
interface ClientOptions {
|
|
89
|
-
fetch?: FetchFn;
|
|
138
|
+
fetch?: FetchFn$1;
|
|
90
139
|
}
|
|
91
140
|
declare class Client {
|
|
92
141
|
#private;
|
|
93
142
|
constructor(baseURL: string, options?: ClientOptions);
|
|
94
143
|
/** Fetch a snapshot of all NMEA 2000 devices discovered by the server. */
|
|
95
144
|
devices(signal?: AbortSignal): Promise<Device[]>;
|
|
145
|
+
/** Fetch the last-seen value for each (device, PGN) pair. */
|
|
146
|
+
values(signal?: AbortSignal): Promise<DeviceValues[]>;
|
|
96
147
|
/**
|
|
97
148
|
* Open an ephemeral SSE stream with optional filtering.
|
|
98
149
|
* No session, no replay, no ACK.
|
|
@@ -104,6 +155,33 @@ declare class Client {
|
|
|
104
155
|
createSession(config: SessionConfig, signal?: AbortSignal): Promise<Session>;
|
|
105
156
|
}
|
|
106
157
|
|
|
158
|
+
type FetchFn = typeof globalThis.fetch;
|
|
159
|
+
interface CloudClientOptions {
|
|
160
|
+
fetch?: FetchFn;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Client for the lplex-cloud management API.
|
|
164
|
+
*
|
|
165
|
+
* For per-instance data (devices, SSE), use {@link client} to get a
|
|
166
|
+
* regular {@link Client} scoped to that instance.
|
|
167
|
+
*/
|
|
168
|
+
declare class CloudClient {
|
|
169
|
+
#private;
|
|
170
|
+
constructor(baseURL: string, options?: CloudClientOptions);
|
|
171
|
+
/**
|
|
172
|
+
* Returns a {@link Client} scoped to a specific instance.
|
|
173
|
+
* The returned client's `devices()`, `subscribe()`, etc. hit the
|
|
174
|
+
* cloud's per-instance endpoints.
|
|
175
|
+
*/
|
|
176
|
+
client(instanceId: string): Client;
|
|
177
|
+
/** List all known instances. */
|
|
178
|
+
instances(signal?: AbortSignal): Promise<InstanceSummary[]>;
|
|
179
|
+
/** Get detailed replication status for one instance. */
|
|
180
|
+
status(instanceId: string, signal?: AbortSignal): Promise<InstanceStatus>;
|
|
181
|
+
/** Fetch recent replication diagnostic events for an instance. */
|
|
182
|
+
replicationEvents(instanceId: string, limit?: number, signal?: AbortSignal): Promise<ReplicationEvent[]>;
|
|
183
|
+
}
|
|
184
|
+
|
|
107
185
|
declare class LplexError extends Error {
|
|
108
186
|
constructor(message: string);
|
|
109
187
|
}
|
|
@@ -113,4 +191,4 @@ declare class HttpError extends LplexError {
|
|
|
113
191
|
constructor(method: string, path: string, status: number, body: string);
|
|
114
192
|
}
|
|
115
193
|
|
|
116
|
-
export { Client, type ClientOptions, type Device, type Event, type Filter, type Frame, HttpError, LplexError, type SendParams, Session, type SessionConfig, type SessionInfo };
|
|
194
|
+
export { Client, type ClientOptions, CloudClient, type CloudClientOptions, type Device, type DeviceValues, type Event, type Filter, type Frame, HttpError, type InstanceStatus, type InstanceSummary, LplexError, type PGNValue, type ReplicationEvent, type ReplicationEventType, type SendParams, type SeqRange, Session, type SessionConfig, type SessionInfo };
|
package/dist/index.d.ts
CHANGED
|
@@ -67,12 +67,61 @@ interface SendParams {
|
|
|
67
67
|
prio: number;
|
|
68
68
|
data: string;
|
|
69
69
|
}
|
|
70
|
+
/** A single PGN's last-known value for a device. */
|
|
71
|
+
interface PGNValue {
|
|
72
|
+
pgn: number;
|
|
73
|
+
ts: string;
|
|
74
|
+
data: string;
|
|
75
|
+
seq: number;
|
|
76
|
+
}
|
|
77
|
+
/** Last-known values grouped by device. */
|
|
78
|
+
interface DeviceValues {
|
|
79
|
+
name: string;
|
|
80
|
+
src: number;
|
|
81
|
+
manufacturer?: string;
|
|
82
|
+
model_id?: string;
|
|
83
|
+
values: PGNValue[];
|
|
84
|
+
}
|
|
85
|
+
/** Summary of a cloud instance, returned by GET /instances. */
|
|
86
|
+
interface InstanceSummary {
|
|
87
|
+
id: string;
|
|
88
|
+
connected: boolean;
|
|
89
|
+
cursor: number;
|
|
90
|
+
boat_head_seq: number;
|
|
91
|
+
holes: number;
|
|
92
|
+
lag_seqs: number;
|
|
93
|
+
last_seen: string;
|
|
94
|
+
}
|
|
95
|
+
/** A sequence range representing a gap in the replication stream. */
|
|
96
|
+
interface SeqRange {
|
|
97
|
+
start: number;
|
|
98
|
+
end: number;
|
|
99
|
+
}
|
|
100
|
+
/** Detailed replication status for one instance. */
|
|
101
|
+
interface InstanceStatus {
|
|
102
|
+
id: string;
|
|
103
|
+
connected: boolean;
|
|
104
|
+
cursor: number;
|
|
105
|
+
boat_head_seq: number;
|
|
106
|
+
boat_journal_bytes: number;
|
|
107
|
+
holes: SeqRange[];
|
|
108
|
+
lag_seqs: number;
|
|
109
|
+
last_seen: string;
|
|
110
|
+
}
|
|
111
|
+
/** Event types emitted by the replication pipeline. */
|
|
112
|
+
type ReplicationEventType = "live_start" | "live_stop" | "backfill_start" | "backfill_stop" | "block_received" | "checkpoint";
|
|
113
|
+
/** A single diagnostic event from the replication pipeline. */
|
|
114
|
+
interface ReplicationEvent {
|
|
115
|
+
time: string;
|
|
116
|
+
type: ReplicationEventType;
|
|
117
|
+
detail?: Record<string, unknown>;
|
|
118
|
+
}
|
|
70
119
|
|
|
71
|
-
type FetchFn$
|
|
120
|
+
type FetchFn$2 = typeof globalThis.fetch;
|
|
72
121
|
declare class Session {
|
|
73
122
|
#private;
|
|
74
123
|
/** @internal Created by Client.createSession, not for direct use. */
|
|
75
|
-
constructor(baseURL: string, fetchFn: FetchFn$
|
|
124
|
+
constructor(baseURL: string, fetchFn: FetchFn$2, info: SessionInfo);
|
|
76
125
|
get info(): SessionInfo;
|
|
77
126
|
get lastAckedSeq(): number;
|
|
78
127
|
/**
|
|
@@ -84,15 +133,17 @@ declare class Session {
|
|
|
84
133
|
ack(seq: number, signal?: AbortSignal): Promise<void>;
|
|
85
134
|
}
|
|
86
135
|
|
|
87
|
-
type FetchFn = typeof globalThis.fetch;
|
|
136
|
+
type FetchFn$1 = typeof globalThis.fetch;
|
|
88
137
|
interface ClientOptions {
|
|
89
|
-
fetch?: FetchFn;
|
|
138
|
+
fetch?: FetchFn$1;
|
|
90
139
|
}
|
|
91
140
|
declare class Client {
|
|
92
141
|
#private;
|
|
93
142
|
constructor(baseURL: string, options?: ClientOptions);
|
|
94
143
|
/** Fetch a snapshot of all NMEA 2000 devices discovered by the server. */
|
|
95
144
|
devices(signal?: AbortSignal): Promise<Device[]>;
|
|
145
|
+
/** Fetch the last-seen value for each (device, PGN) pair. */
|
|
146
|
+
values(signal?: AbortSignal): Promise<DeviceValues[]>;
|
|
96
147
|
/**
|
|
97
148
|
* Open an ephemeral SSE stream with optional filtering.
|
|
98
149
|
* No session, no replay, no ACK.
|
|
@@ -104,6 +155,33 @@ declare class Client {
|
|
|
104
155
|
createSession(config: SessionConfig, signal?: AbortSignal): Promise<Session>;
|
|
105
156
|
}
|
|
106
157
|
|
|
158
|
+
type FetchFn = typeof globalThis.fetch;
|
|
159
|
+
interface CloudClientOptions {
|
|
160
|
+
fetch?: FetchFn;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Client for the lplex-cloud management API.
|
|
164
|
+
*
|
|
165
|
+
* For per-instance data (devices, SSE), use {@link client} to get a
|
|
166
|
+
* regular {@link Client} scoped to that instance.
|
|
167
|
+
*/
|
|
168
|
+
declare class CloudClient {
|
|
169
|
+
#private;
|
|
170
|
+
constructor(baseURL: string, options?: CloudClientOptions);
|
|
171
|
+
/**
|
|
172
|
+
* Returns a {@link Client} scoped to a specific instance.
|
|
173
|
+
* The returned client's `devices()`, `subscribe()`, etc. hit the
|
|
174
|
+
* cloud's per-instance endpoints.
|
|
175
|
+
*/
|
|
176
|
+
client(instanceId: string): Client;
|
|
177
|
+
/** List all known instances. */
|
|
178
|
+
instances(signal?: AbortSignal): Promise<InstanceSummary[]>;
|
|
179
|
+
/** Get detailed replication status for one instance. */
|
|
180
|
+
status(instanceId: string, signal?: AbortSignal): Promise<InstanceStatus>;
|
|
181
|
+
/** Fetch recent replication diagnostic events for an instance. */
|
|
182
|
+
replicationEvents(instanceId: string, limit?: number, signal?: AbortSignal): Promise<ReplicationEvent[]>;
|
|
183
|
+
}
|
|
184
|
+
|
|
107
185
|
declare class LplexError extends Error {
|
|
108
186
|
constructor(message: string);
|
|
109
187
|
}
|
|
@@ -113,4 +191,4 @@ declare class HttpError extends LplexError {
|
|
|
113
191
|
constructor(method: string, path: string, status: number, body: string);
|
|
114
192
|
}
|
|
115
193
|
|
|
116
|
-
export { Client, type ClientOptions, type Device, type Event, type Filter, type Frame, HttpError, LplexError, type SendParams, Session, type SessionConfig, type SessionInfo };
|
|
194
|
+
export { Client, type ClientOptions, CloudClient, type CloudClientOptions, type Device, type DeviceValues, type Event, type Filter, type Frame, HttpError, type InstanceStatus, type InstanceSummary, LplexError, type PGNValue, type ReplicationEvent, type ReplicationEventType, type SendParams, type SeqRange, Session, type SessionConfig, type SessionInfo };
|
package/dist/index.js
CHANGED
|
@@ -140,6 +140,16 @@ var Client = class {
|
|
|
140
140
|
}
|
|
141
141
|
return resp.json();
|
|
142
142
|
}
|
|
143
|
+
/** Fetch the last-seen value for each (device, PGN) pair. */
|
|
144
|
+
async values(signal) {
|
|
145
|
+
const url = `${this.#baseURL}/values`;
|
|
146
|
+
const resp = await this.#fetch(url, { signal });
|
|
147
|
+
if (!resp.ok) {
|
|
148
|
+
const body = await resp.text();
|
|
149
|
+
throw new HttpError("GET", url, resp.status, body);
|
|
150
|
+
}
|
|
151
|
+
return resp.json();
|
|
152
|
+
}
|
|
143
153
|
/**
|
|
144
154
|
* Open an ephemeral SSE stream with optional filtering.
|
|
145
155
|
* No session, no replay, no ACK.
|
|
@@ -218,8 +228,63 @@ function filterToJSON(f) {
|
|
|
218
228
|
if (f.name?.length) m.name = f.name;
|
|
219
229
|
return m;
|
|
220
230
|
}
|
|
231
|
+
|
|
232
|
+
// src/cloud.ts
|
|
233
|
+
var CloudClient = class {
|
|
234
|
+
#baseURL;
|
|
235
|
+
#fetch;
|
|
236
|
+
#fetchOpt;
|
|
237
|
+
constructor(baseURL, options) {
|
|
238
|
+
this.#baseURL = baseURL.replace(/\/+$/, "");
|
|
239
|
+
this.#fetch = options?.fetch ?? globalThis.fetch.bind(globalThis);
|
|
240
|
+
this.#fetchOpt = options ?? {};
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Returns a {@link Client} scoped to a specific instance.
|
|
244
|
+
* The returned client's `devices()`, `subscribe()`, etc. hit the
|
|
245
|
+
* cloud's per-instance endpoints.
|
|
246
|
+
*/
|
|
247
|
+
client(instanceId) {
|
|
248
|
+
const opts = {};
|
|
249
|
+
if (this.#fetchOpt.fetch) opts.fetch = this.#fetchOpt.fetch;
|
|
250
|
+
return new Client(`${this.#baseURL}/instances/${instanceId}`, opts);
|
|
251
|
+
}
|
|
252
|
+
/** List all known instances. */
|
|
253
|
+
async instances(signal) {
|
|
254
|
+
const url = `${this.#baseURL}/instances`;
|
|
255
|
+
const resp = await this.#fetch(url, { signal });
|
|
256
|
+
if (!resp.ok) {
|
|
257
|
+
const body = await resp.text();
|
|
258
|
+
throw new HttpError("GET", url, resp.status, body);
|
|
259
|
+
}
|
|
260
|
+
const data = await resp.json();
|
|
261
|
+
return data.instances;
|
|
262
|
+
}
|
|
263
|
+
/** Get detailed replication status for one instance. */
|
|
264
|
+
async status(instanceId, signal) {
|
|
265
|
+
const url = `${this.#baseURL}/instances/${instanceId}/status`;
|
|
266
|
+
const resp = await this.#fetch(url, { signal });
|
|
267
|
+
if (!resp.ok) {
|
|
268
|
+
const body = await resp.text();
|
|
269
|
+
throw new HttpError("GET", url, resp.status, body);
|
|
270
|
+
}
|
|
271
|
+
return resp.json();
|
|
272
|
+
}
|
|
273
|
+
/** Fetch recent replication diagnostic events for an instance. */
|
|
274
|
+
async replicationEvents(instanceId, limit, signal) {
|
|
275
|
+
let url = `${this.#baseURL}/instances/${instanceId}/replication/events`;
|
|
276
|
+
if (limit !== void 0) url += `?limit=${limit}`;
|
|
277
|
+
const resp = await this.#fetch(url, { signal });
|
|
278
|
+
if (!resp.ok) {
|
|
279
|
+
const body = await resp.text();
|
|
280
|
+
throw new HttpError("GET", url, resp.status, body);
|
|
281
|
+
}
|
|
282
|
+
return resp.json();
|
|
283
|
+
}
|
|
284
|
+
};
|
|
221
285
|
export {
|
|
222
286
|
Client,
|
|
287
|
+
CloudClient,
|
|
223
288
|
HttpError,
|
|
224
289
|
LplexError,
|
|
225
290
|
Session
|