@meshagent/meshagent 0.29.2 → 0.30.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/CHANGELOG.md +12 -0
- package/dist/browser/agent-client.js +3 -28
- package/dist/browser/agent.js +6 -6
- package/dist/browser/containers-client.d.ts +125 -0
- package/dist/browser/containers-client.js +458 -0
- package/dist/browser/database-client.d.ts +42 -6
- package/dist/browser/database-client.js +610 -77
- package/dist/browser/developer-client.d.ts +2 -2
- package/dist/browser/developer-client.js +60 -15
- package/dist/browser/helpers.js +4 -3
- package/dist/browser/index.d.ts +1 -0
- package/dist/browser/index.js +1 -0
- package/dist/browser/lk-client.js +12 -3
- package/dist/browser/meshagent-client.d.ts +5 -0
- package/dist/browser/messaging-client.d.ts +1 -0
- package/dist/browser/messaging-client.js +52 -8
- package/dist/browser/queues-client.d.ts +2 -0
- package/dist/browser/queues-client.js +34 -7
- package/dist/browser/response.d.ts +28 -0
- package/dist/browser/response.js +76 -1
- package/dist/browser/room-client.d.ts +43 -1
- package/dist/browser/room-client.js +204 -0
- package/dist/browser/secrets-client.d.ts +1 -0
- package/dist/browser/secrets-client.js +32 -27
- package/dist/browser/storage-client.d.ts +22 -7
- package/dist/browser/storage-client.js +353 -15
- package/dist/browser/sync-client.d.ts +12 -13
- package/dist/browser/sync-client.js +263 -65
- package/dist/esm/agent-client.js +3 -28
- package/dist/esm/agent.js +6 -6
- package/dist/esm/containers-client.d.ts +125 -0
- package/dist/esm/containers-client.js +453 -0
- package/dist/esm/database-client.d.ts +42 -6
- package/dist/esm/database-client.js +611 -78
- package/dist/esm/developer-client.d.ts +2 -2
- package/dist/esm/developer-client.js +61 -16
- package/dist/esm/helpers.js +4 -3
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/lk-client.js +12 -3
- package/dist/esm/meshagent-client.d.ts +5 -0
- package/dist/esm/messaging-client.d.ts +1 -0
- package/dist/esm/messaging-client.js +52 -8
- package/dist/esm/queues-client.d.ts +2 -0
- package/dist/esm/queues-client.js +35 -8
- package/dist/esm/response.d.ts +28 -0
- package/dist/esm/response.js +73 -0
- package/dist/esm/room-client.d.ts +43 -1
- package/dist/esm/room-client.js +207 -3
- package/dist/esm/secrets-client.d.ts +1 -0
- package/dist/esm/secrets-client.js +33 -28
- package/dist/esm/storage-client.d.ts +22 -7
- package/dist/esm/storage-client.js +353 -15
- package/dist/esm/sync-client.d.ts +12 -13
- package/dist/esm/sync-client.js +263 -64
- package/dist/node/agent-client.js +3 -28
- package/dist/node/agent.js +6 -6
- package/dist/node/containers-client.d.ts +125 -0
- package/dist/node/containers-client.js +458 -0
- package/dist/node/database-client.d.ts +42 -6
- package/dist/node/database-client.js +610 -77
- package/dist/node/developer-client.d.ts +2 -2
- package/dist/node/developer-client.js +60 -15
- package/dist/node/helpers.js +4 -3
- package/dist/node/index.d.ts +1 -0
- package/dist/node/index.js +1 -0
- package/dist/node/lk-client.js +12 -3
- package/dist/node/meshagent-client.d.ts +5 -0
- package/dist/node/messaging-client.d.ts +1 -0
- package/dist/node/messaging-client.js +52 -8
- package/dist/node/queues-client.d.ts +2 -0
- package/dist/node/queues-client.js +34 -7
- package/dist/node/response.d.ts +28 -0
- package/dist/node/response.js +76 -1
- package/dist/node/room-client.d.ts +43 -1
- package/dist/node/room-client.js +204 -0
- package/dist/node/secrets-client.d.ts +1 -0
- package/dist/node/secrets-client.js +32 -27
- package/dist/node/storage-client.d.ts +22 -7
- package/dist/node/storage-client.js +353 -15
- package/dist/node/sync-client.d.ts +12 -13
- package/dist/node/sync-client.js +263 -65
- package/package.json +1 -1
|
@@ -0,0 +1,458 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ContainersClient = exports.ExecSession = void 0;
|
|
4
|
+
const uuid_1 = require("uuid");
|
|
5
|
+
const completer_1 = require("./completer");
|
|
6
|
+
const response_1 = require("./response");
|
|
7
|
+
const room_server_client_1 = require("./room-server-client");
|
|
8
|
+
const stream_controller_1 = require("./stream-controller");
|
|
9
|
+
function isRecord(value) {
|
|
10
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
11
|
+
}
|
|
12
|
+
function toStringMapList(values) {
|
|
13
|
+
return Object.entries(values).map(([key, value]) => ({ key, value }));
|
|
14
|
+
}
|
|
15
|
+
function toPortPairs(values) {
|
|
16
|
+
return Object.entries(values).map(([containerPort, hostPort]) => ({
|
|
17
|
+
container_port: Number(containerPort),
|
|
18
|
+
host_port: hostPort,
|
|
19
|
+
}));
|
|
20
|
+
}
|
|
21
|
+
function toCredentials(values) {
|
|
22
|
+
return values.map((entry) => ({
|
|
23
|
+
registry: entry.registry,
|
|
24
|
+
username: entry.username,
|
|
25
|
+
password: entry.password,
|
|
26
|
+
}));
|
|
27
|
+
}
|
|
28
|
+
function readStringField(data, field, operation) {
|
|
29
|
+
const value = data[field];
|
|
30
|
+
if (typeof value !== "string") {
|
|
31
|
+
throw new room_server_client_1.RoomServerException(`unexpected return type from containers.${operation}`);
|
|
32
|
+
}
|
|
33
|
+
return value;
|
|
34
|
+
}
|
|
35
|
+
function decodeJsonStatus(data) {
|
|
36
|
+
const text = new TextDecoder().decode(data);
|
|
37
|
+
let parsed;
|
|
38
|
+
try {
|
|
39
|
+
parsed = JSON.parse(text);
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
throw new room_server_client_1.RoomServerException("containers.exec returned an invalid status payload");
|
|
43
|
+
}
|
|
44
|
+
if (!isRecord(parsed)) {
|
|
45
|
+
throw new room_server_client_1.RoomServerException("containers.exec returned an invalid status payload");
|
|
46
|
+
}
|
|
47
|
+
const status = parsed["status"];
|
|
48
|
+
if (typeof status !== "number" || !Number.isInteger(status)) {
|
|
49
|
+
throw new room_server_client_1.RoomServerException("containers.exec returned an invalid status payload");
|
|
50
|
+
}
|
|
51
|
+
return status;
|
|
52
|
+
}
|
|
53
|
+
class ExecSession {
|
|
54
|
+
constructor(params) {
|
|
55
|
+
this.previousOutput = [];
|
|
56
|
+
this.resultCompleter = new completer_1.Completer();
|
|
57
|
+
this.outputController = new stream_controller_1.StreamController();
|
|
58
|
+
this.queuedInput = [];
|
|
59
|
+
this.inputClosed = false;
|
|
60
|
+
this.closed = false;
|
|
61
|
+
this.inputWaiter = null;
|
|
62
|
+
this.requestId = params.requestId;
|
|
63
|
+
this.command = params.command;
|
|
64
|
+
this.containerId = params.containerId;
|
|
65
|
+
this.tty = params.tty;
|
|
66
|
+
this.result = this.resultCompleter.fut;
|
|
67
|
+
this.output = this.outputController.stream;
|
|
68
|
+
}
|
|
69
|
+
async *inputStream() {
|
|
70
|
+
yield new response_1.BinaryContent({
|
|
71
|
+
data: new Uint8Array(0),
|
|
72
|
+
headers: {
|
|
73
|
+
kind: "start",
|
|
74
|
+
request_id: this.requestId,
|
|
75
|
+
container_id: this.containerId,
|
|
76
|
+
command: this.command,
|
|
77
|
+
tty: this.tty,
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
while (true) {
|
|
81
|
+
while (this.queuedInput.length > 0) {
|
|
82
|
+
const chunk = this.queuedInput.shift();
|
|
83
|
+
if (chunk) {
|
|
84
|
+
yield chunk;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (this.inputClosed) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
this.inputWaiter = new completer_1.Completer();
|
|
91
|
+
await this.inputWaiter.fut;
|
|
92
|
+
this.inputWaiter = null;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
async write(data) {
|
|
96
|
+
this.queueInput({ channel: 1, data });
|
|
97
|
+
}
|
|
98
|
+
async resize(params) {
|
|
99
|
+
if (this.lastResizeWidth === params.width && this.lastResizeHeight === params.height) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
this.lastResizeWidth = params.width;
|
|
103
|
+
this.lastResizeHeight = params.height;
|
|
104
|
+
this.queueInput({ channel: 4, width: params.width, height: params.height });
|
|
105
|
+
}
|
|
106
|
+
async stop() {
|
|
107
|
+
this.closeInputStream();
|
|
108
|
+
}
|
|
109
|
+
async kill() {
|
|
110
|
+
if (this.inputClosed) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
this.queueInput({ channel: 5 });
|
|
114
|
+
}
|
|
115
|
+
close(status) {
|
|
116
|
+
if (!this.resultCompleter.completed) {
|
|
117
|
+
this.resultCompleter.complete(status);
|
|
118
|
+
}
|
|
119
|
+
this.closed = true;
|
|
120
|
+
this.closeInputStream();
|
|
121
|
+
this.outputController.close();
|
|
122
|
+
}
|
|
123
|
+
closeError(error) {
|
|
124
|
+
if (!this.resultCompleter.completed) {
|
|
125
|
+
this.resultCompleter.completeError(error);
|
|
126
|
+
}
|
|
127
|
+
this.closed = true;
|
|
128
|
+
this.closeInputStream();
|
|
129
|
+
this.outputController.close();
|
|
130
|
+
}
|
|
131
|
+
addOutput(data) {
|
|
132
|
+
this.previousOutput.push(data);
|
|
133
|
+
this.outputController.add(data);
|
|
134
|
+
}
|
|
135
|
+
get isClosed() {
|
|
136
|
+
return this.closed;
|
|
137
|
+
}
|
|
138
|
+
queueInput(params) {
|
|
139
|
+
if (this.inputClosed) {
|
|
140
|
+
throw new room_server_client_1.RoomServerException("container exec session is already closed");
|
|
141
|
+
}
|
|
142
|
+
this.queuedInput.push(new response_1.BinaryContent({
|
|
143
|
+
data: params.data ?? new Uint8Array(0),
|
|
144
|
+
headers: {
|
|
145
|
+
kind: "input",
|
|
146
|
+
channel: params.channel,
|
|
147
|
+
width: params.width,
|
|
148
|
+
height: params.height,
|
|
149
|
+
},
|
|
150
|
+
}));
|
|
151
|
+
this.inputWaiter?.complete();
|
|
152
|
+
}
|
|
153
|
+
closeInputStream() {
|
|
154
|
+
if (this.inputClosed) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
this.inputClosed = true;
|
|
158
|
+
this.inputWaiter?.complete();
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
exports.ExecSession = ExecSession;
|
|
162
|
+
class ContainersClient {
|
|
163
|
+
constructor({ room }) {
|
|
164
|
+
this.room = room;
|
|
165
|
+
}
|
|
166
|
+
unexpectedResponseError(operation) {
|
|
167
|
+
return new room_server_client_1.RoomServerException(`unexpected return type from containers.${operation}`);
|
|
168
|
+
}
|
|
169
|
+
async invoke(operation, input) {
|
|
170
|
+
return await this.room.invoke({
|
|
171
|
+
toolkit: "containers",
|
|
172
|
+
tool: operation,
|
|
173
|
+
input,
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
async listImages() {
|
|
177
|
+
const output = await this.invoke("list_images", {});
|
|
178
|
+
if (!(output instanceof response_1.JsonContent)) {
|
|
179
|
+
throw this.unexpectedResponseError("list_images");
|
|
180
|
+
}
|
|
181
|
+
const imagesRaw = output.json["images"];
|
|
182
|
+
if (!Array.isArray(imagesRaw)) {
|
|
183
|
+
throw this.unexpectedResponseError("list_images");
|
|
184
|
+
}
|
|
185
|
+
const images = [];
|
|
186
|
+
for (const entry of imagesRaw) {
|
|
187
|
+
if (!isRecord(entry)) {
|
|
188
|
+
throw this.unexpectedResponseError("list_images");
|
|
189
|
+
}
|
|
190
|
+
const id = entry["id"];
|
|
191
|
+
const tags = entry["tags"];
|
|
192
|
+
const labelsRaw = entry["labels"];
|
|
193
|
+
if (typeof id !== "string" || !Array.isArray(tags)) {
|
|
194
|
+
throw this.unexpectedResponseError("list_images");
|
|
195
|
+
}
|
|
196
|
+
const normalizedTags = tags.filter((tag) => typeof tag === "string");
|
|
197
|
+
const size = entry["size"];
|
|
198
|
+
images.push({
|
|
199
|
+
id,
|
|
200
|
+
tags: normalizedTags,
|
|
201
|
+
size: typeof size === "number" ? size : undefined,
|
|
202
|
+
labels: isRecord(labelsRaw) ? labelsRaw : {},
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
return images;
|
|
206
|
+
}
|
|
207
|
+
async pullImage(params) {
|
|
208
|
+
await this.invoke("pull_image", {
|
|
209
|
+
tag: params.tag,
|
|
210
|
+
credentials: toCredentials(params.credentials ?? []),
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
async run(params) {
|
|
214
|
+
const output = await this.invoke("run", {
|
|
215
|
+
image: params.image,
|
|
216
|
+
command: params.command,
|
|
217
|
+
working_dir: params.workingDir,
|
|
218
|
+
env: toStringMapList(params.env ?? {}),
|
|
219
|
+
mount_path: params.mountPath,
|
|
220
|
+
mount_subpath: params.mountSubpath,
|
|
221
|
+
role: params.role,
|
|
222
|
+
participant_name: params.participantName,
|
|
223
|
+
ports: toPortPairs(params.ports ?? {}),
|
|
224
|
+
credentials: toCredentials(params.credentials ?? []),
|
|
225
|
+
name: params.name,
|
|
226
|
+
mounts: params.mounts,
|
|
227
|
+
writable_root_fs: params.writableRootFs,
|
|
228
|
+
private: params.private,
|
|
229
|
+
});
|
|
230
|
+
if (!(output instanceof response_1.JsonContent) || !isRecord(output.json)) {
|
|
231
|
+
throw this.unexpectedResponseError("run");
|
|
232
|
+
}
|
|
233
|
+
return readStringField(output.json, "container_id", "run");
|
|
234
|
+
}
|
|
235
|
+
async runService(params) {
|
|
236
|
+
const output = await this.invoke("run_service", {
|
|
237
|
+
service_id: params.serviceId,
|
|
238
|
+
env: toStringMapList(params.env ?? {}),
|
|
239
|
+
});
|
|
240
|
+
if (!(output instanceof response_1.JsonContent) || !isRecord(output.json)) {
|
|
241
|
+
throw this.unexpectedResponseError("run_service");
|
|
242
|
+
}
|
|
243
|
+
return readStringField(output.json, "container_id", "run_service");
|
|
244
|
+
}
|
|
245
|
+
exec(params) {
|
|
246
|
+
const requestId = (0, uuid_1.v4)();
|
|
247
|
+
const session = new ExecSession({
|
|
248
|
+
requestId,
|
|
249
|
+
command: params.command,
|
|
250
|
+
containerId: params.containerId,
|
|
251
|
+
tty: params.tty,
|
|
252
|
+
});
|
|
253
|
+
this.room
|
|
254
|
+
.invokeStream({
|
|
255
|
+
toolkit: "containers",
|
|
256
|
+
tool: "exec",
|
|
257
|
+
input: session.inputStream(),
|
|
258
|
+
})
|
|
259
|
+
.then(async (stream) => {
|
|
260
|
+
for await (const chunk of stream) {
|
|
261
|
+
if (chunk instanceof response_1.ErrorContent) {
|
|
262
|
+
throw new room_server_client_1.RoomServerException(chunk.text, chunk.code);
|
|
263
|
+
}
|
|
264
|
+
if (!(chunk instanceof response_1.BinaryContent)) {
|
|
265
|
+
throw this.unexpectedResponseError("exec");
|
|
266
|
+
}
|
|
267
|
+
const channel = chunk.headers["channel"];
|
|
268
|
+
if (typeof channel !== "number") {
|
|
269
|
+
throw new room_server_client_1.RoomServerException("containers.exec returned a chunk without a valid channel");
|
|
270
|
+
}
|
|
271
|
+
if (channel === 1) {
|
|
272
|
+
session.addOutput(chunk.data);
|
|
273
|
+
continue;
|
|
274
|
+
}
|
|
275
|
+
if (channel === 3) {
|
|
276
|
+
session.close(decodeJsonStatus(chunk.data));
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
throw new room_server_client_1.RoomServerException("containers.exec stream closed before a status was returned");
|
|
281
|
+
})
|
|
282
|
+
.catch((error) => {
|
|
283
|
+
session.closeError(error);
|
|
284
|
+
});
|
|
285
|
+
return session;
|
|
286
|
+
}
|
|
287
|
+
async stop(params) {
|
|
288
|
+
await this.invoke("stop_container", {
|
|
289
|
+
container_id: params.containerId,
|
|
290
|
+
force: params.force ?? true,
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
async waitForExit(params) {
|
|
294
|
+
const output = await this.invoke("wait_for_exit", {
|
|
295
|
+
container_id: params.containerId,
|
|
296
|
+
});
|
|
297
|
+
if (!(output instanceof response_1.JsonContent) || !isRecord(output.json)) {
|
|
298
|
+
throw this.unexpectedResponseError("wait_for_exit");
|
|
299
|
+
}
|
|
300
|
+
const exitCode = output.json["exit_code"];
|
|
301
|
+
if (typeof exitCode !== "number" || !Number.isInteger(exitCode)) {
|
|
302
|
+
throw this.unexpectedResponseError("wait_for_exit");
|
|
303
|
+
}
|
|
304
|
+
return exitCode;
|
|
305
|
+
}
|
|
306
|
+
async deleteContainer(params) {
|
|
307
|
+
await this.invoke("delete_container", {
|
|
308
|
+
container_id: params.containerId,
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
logs(params) {
|
|
312
|
+
const requestId = (0, uuid_1.v4)();
|
|
313
|
+
const closeInput = new completer_1.Completer();
|
|
314
|
+
const streamController = new stream_controller_1.StreamController();
|
|
315
|
+
const result = new completer_1.Completer();
|
|
316
|
+
let inputClosed = false;
|
|
317
|
+
const closeInputStream = () => {
|
|
318
|
+
if (inputClosed) {
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
inputClosed = true;
|
|
322
|
+
if (!closeInput.completed) {
|
|
323
|
+
closeInput.complete();
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
const inputStream = async function* () {
|
|
327
|
+
yield new response_1.BinaryContent({
|
|
328
|
+
data: new Uint8Array(0),
|
|
329
|
+
headers: {
|
|
330
|
+
kind: "start",
|
|
331
|
+
request_id: requestId,
|
|
332
|
+
container_id: params.containerId,
|
|
333
|
+
follow: params.follow ?? false,
|
|
334
|
+
},
|
|
335
|
+
});
|
|
336
|
+
await closeInput.fut;
|
|
337
|
+
};
|
|
338
|
+
this.room
|
|
339
|
+
.invokeStream({
|
|
340
|
+
toolkit: "containers",
|
|
341
|
+
tool: "logs",
|
|
342
|
+
input: inputStream(),
|
|
343
|
+
})
|
|
344
|
+
.then(async (stream) => {
|
|
345
|
+
const decoder = new TextDecoder();
|
|
346
|
+
for await (const chunk of stream) {
|
|
347
|
+
if (chunk instanceof response_1.ErrorContent) {
|
|
348
|
+
throw new room_server_client_1.RoomServerException(chunk.text, chunk.code);
|
|
349
|
+
}
|
|
350
|
+
if (chunk instanceof response_1.ControlContent) {
|
|
351
|
+
continue;
|
|
352
|
+
}
|
|
353
|
+
if (!(chunk instanceof response_1.BinaryContent)) {
|
|
354
|
+
throw this.unexpectedResponseError("logs");
|
|
355
|
+
}
|
|
356
|
+
const channel = chunk.headers["channel"];
|
|
357
|
+
if (typeof channel !== "number") {
|
|
358
|
+
throw new room_server_client_1.RoomServerException("containers.logs returned a chunk without a valid channel");
|
|
359
|
+
}
|
|
360
|
+
if (channel !== 1) {
|
|
361
|
+
continue;
|
|
362
|
+
}
|
|
363
|
+
streamController.add(decoder.decode(chunk.data));
|
|
364
|
+
}
|
|
365
|
+
closeInputStream();
|
|
366
|
+
streamController.close();
|
|
367
|
+
result.complete();
|
|
368
|
+
})
|
|
369
|
+
.catch((error) => {
|
|
370
|
+
closeInputStream();
|
|
371
|
+
streamController.close();
|
|
372
|
+
if (!result.completed) {
|
|
373
|
+
result.completeError(error);
|
|
374
|
+
}
|
|
375
|
+
});
|
|
376
|
+
const outputStream = {
|
|
377
|
+
[Symbol.asyncIterator]() {
|
|
378
|
+
const it = streamController.stream[Symbol.asyncIterator]();
|
|
379
|
+
return {
|
|
380
|
+
async next() {
|
|
381
|
+
return await it.next();
|
|
382
|
+
},
|
|
383
|
+
async return(value) {
|
|
384
|
+
closeInputStream();
|
|
385
|
+
return await it.return?.(value) ?? { done: true, value };
|
|
386
|
+
},
|
|
387
|
+
async throw(e) {
|
|
388
|
+
closeInputStream();
|
|
389
|
+
if (it.throw) {
|
|
390
|
+
return await it.throw(e);
|
|
391
|
+
}
|
|
392
|
+
throw e;
|
|
393
|
+
},
|
|
394
|
+
};
|
|
395
|
+
},
|
|
396
|
+
};
|
|
397
|
+
return {
|
|
398
|
+
stream: outputStream,
|
|
399
|
+
result: result.fut,
|
|
400
|
+
cancel: async () => {
|
|
401
|
+
closeInputStream();
|
|
402
|
+
await result.fut.catch(() => undefined);
|
|
403
|
+
},
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
async list(params) {
|
|
407
|
+
const output = await this.invoke("list_containers", {
|
|
408
|
+
all: params?.all,
|
|
409
|
+
});
|
|
410
|
+
if (!(output instanceof response_1.JsonContent) || !isRecord(output.json)) {
|
|
411
|
+
throw this.unexpectedResponseError("list");
|
|
412
|
+
}
|
|
413
|
+
const containersRaw = output.json["containers"];
|
|
414
|
+
if (!Array.isArray(containersRaw)) {
|
|
415
|
+
throw this.unexpectedResponseError("list");
|
|
416
|
+
}
|
|
417
|
+
const items = [];
|
|
418
|
+
for (const entry of containersRaw) {
|
|
419
|
+
if (!isRecord(entry)) {
|
|
420
|
+
throw this.unexpectedResponseError("list");
|
|
421
|
+
}
|
|
422
|
+
const startedByRaw = entry["started_by"];
|
|
423
|
+
if (!isRecord(startedByRaw)) {
|
|
424
|
+
throw this.unexpectedResponseError("list");
|
|
425
|
+
}
|
|
426
|
+
const id = entry["id"];
|
|
427
|
+
const image = entry["image"];
|
|
428
|
+
const state = entry["state"];
|
|
429
|
+
const privateFlag = entry["private"];
|
|
430
|
+
const startedById = startedByRaw["id"];
|
|
431
|
+
const startedByName = startedByRaw["name"];
|
|
432
|
+
if (typeof id !== "string" ||
|
|
433
|
+
typeof image !== "string" ||
|
|
434
|
+
typeof state !== "string" ||
|
|
435
|
+
typeof privateFlag !== "boolean" ||
|
|
436
|
+
typeof startedById !== "string" ||
|
|
437
|
+
typeof startedByName !== "string") {
|
|
438
|
+
throw this.unexpectedResponseError("list");
|
|
439
|
+
}
|
|
440
|
+
const nameRaw = entry["name"];
|
|
441
|
+
const serviceIdRaw = entry["service_id"];
|
|
442
|
+
items.push({
|
|
443
|
+
id,
|
|
444
|
+
image,
|
|
445
|
+
name: typeof nameRaw === "string" ? nameRaw : undefined,
|
|
446
|
+
startedBy: {
|
|
447
|
+
id: startedById,
|
|
448
|
+
name: startedByName,
|
|
449
|
+
},
|
|
450
|
+
state,
|
|
451
|
+
private: privateFlag,
|
|
452
|
+
serviceId: typeof serviceIdRaw === "string" ? serviceIdRaw : undefined,
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
return items;
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
exports.ContainersClient = ContainersClient;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { RoomClient } from "./room-client";
|
|
2
1
|
import { DataType } from "./data-types";
|
|
2
|
+
import { RoomClient } from "./room-client";
|
|
3
3
|
export type CreateMode = "create" | "overwrite" | "create_if_not_exists";
|
|
4
4
|
export interface TableRef {
|
|
5
5
|
name: string;
|
|
@@ -11,6 +11,11 @@ export declare class DatabaseClient {
|
|
|
11
11
|
constructor({ room }: {
|
|
12
12
|
room: RoomClient;
|
|
13
13
|
});
|
|
14
|
+
private _unexpectedResponseError;
|
|
15
|
+
private invoke;
|
|
16
|
+
private invokeStream;
|
|
17
|
+
private drainWriteStream;
|
|
18
|
+
private streamRows;
|
|
14
19
|
listTables(): Promise<string[]>;
|
|
15
20
|
private createTable;
|
|
16
21
|
createTableWithSchema({ name, schema, data, mode }: {
|
|
@@ -24,6 +29,12 @@ export declare class DatabaseClient {
|
|
|
24
29
|
data?: Array<Record<string, any>>;
|
|
25
30
|
mode?: CreateMode;
|
|
26
31
|
}): Promise<void>;
|
|
32
|
+
createTableFromDataStream({ name, chunks, schema, mode }: {
|
|
33
|
+
name: string;
|
|
34
|
+
chunks: AsyncIterable<Array<Record<string, any>>> | Iterable<Array<Record<string, any>>>;
|
|
35
|
+
schema?: Record<string, DataType>;
|
|
36
|
+
mode?: CreateMode;
|
|
37
|
+
}): Promise<void>;
|
|
27
38
|
dropTable({ name, ignoreMissing }: {
|
|
28
39
|
name: string;
|
|
29
40
|
ignoreMissing?: boolean;
|
|
@@ -40,6 +51,10 @@ export declare class DatabaseClient {
|
|
|
40
51
|
table: string;
|
|
41
52
|
records: Array<Record<string, any>>;
|
|
42
53
|
}): Promise<void>;
|
|
54
|
+
insertStream({ table, chunks }: {
|
|
55
|
+
table: string;
|
|
56
|
+
chunks: AsyncIterable<Array<Record<string, any>>> | Iterable<Array<Record<string, any>>>;
|
|
57
|
+
}): Promise<void>;
|
|
43
58
|
update({ table, where, values, valuesSql }: {
|
|
44
59
|
table: string;
|
|
45
60
|
where: string;
|
|
@@ -53,13 +68,23 @@ export declare class DatabaseClient {
|
|
|
53
68
|
merge({ table, on, records }: {
|
|
54
69
|
table: string;
|
|
55
70
|
on: string;
|
|
56
|
-
records: any
|
|
71
|
+
records: Array<Record<string, any>>;
|
|
72
|
+
}): Promise<void>;
|
|
73
|
+
mergeStream({ table, on, chunks }: {
|
|
74
|
+
table: string;
|
|
75
|
+
on: string;
|
|
76
|
+
chunks: AsyncIterable<Array<Record<string, any>>> | Iterable<Array<Record<string, any>>>;
|
|
57
77
|
}): Promise<void>;
|
|
58
78
|
sql({ query, tables, params }: {
|
|
59
79
|
query: string;
|
|
60
80
|
tables: TableRef[];
|
|
61
81
|
params?: Record<string, any>;
|
|
62
82
|
}): Promise<Array<Record<string, any>>>;
|
|
83
|
+
sqlStream({ query, tables, params }: {
|
|
84
|
+
query: string;
|
|
85
|
+
tables: TableRef[];
|
|
86
|
+
params?: Record<string, any>;
|
|
87
|
+
}): AsyncIterable<Array<Record<string, any>>>;
|
|
63
88
|
search({ table, text, vector, where, limit, select }: {
|
|
64
89
|
table: string;
|
|
65
90
|
text?: string;
|
|
@@ -68,20 +93,31 @@ export declare class DatabaseClient {
|
|
|
68
93
|
limit?: number;
|
|
69
94
|
select?: string[];
|
|
70
95
|
}): Promise<Array<Record<string, any>>>;
|
|
96
|
+
searchStream({ table, text, vector, where, limit, select }: {
|
|
97
|
+
table: string;
|
|
98
|
+
text?: string;
|
|
99
|
+
vector?: number[];
|
|
100
|
+
where?: string | Record<string, any>;
|
|
101
|
+
limit?: number;
|
|
102
|
+
select?: string[];
|
|
103
|
+
}): AsyncIterable<Array<Record<string, any>>>;
|
|
71
104
|
optimize(table: string): Promise<void>;
|
|
72
|
-
createVectorIndex({ table, column }: {
|
|
105
|
+
createVectorIndex({ table, column, replace }: {
|
|
73
106
|
table: string;
|
|
74
107
|
column: string;
|
|
108
|
+
replace?: boolean;
|
|
75
109
|
}): Promise<void>;
|
|
76
|
-
createScalarIndex({ table, column }: {
|
|
110
|
+
createScalarIndex({ table, column, replace }: {
|
|
77
111
|
table: string;
|
|
78
112
|
column: string;
|
|
113
|
+
replace?: boolean;
|
|
79
114
|
}): Promise<void>;
|
|
80
|
-
createFullTextSearchIndex({ table, column }: {
|
|
115
|
+
createFullTextSearchIndex({ table, column, replace }: {
|
|
81
116
|
table: string;
|
|
82
117
|
column: string;
|
|
118
|
+
replace?: boolean;
|
|
83
119
|
}): Promise<void>;
|
|
84
120
|
listIndexes({ table }: {
|
|
85
121
|
table: string;
|
|
86
|
-
}): Promise<Record<string, any
|
|
122
|
+
}): Promise<Array<Record<string, any>>>;
|
|
87
123
|
}
|