@meshagent/meshagent 0.42.2 → 0.43.1
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 +13 -0
- package/dist/browser/agent-client.d.ts +4 -4
- package/dist/browser/agent-client.js +16 -16
- package/dist/browser/agent.d.ts +6 -6
- package/dist/browser/agent.js +57 -57
- package/dist/browser/api_keys.js +7 -3
- package/dist/browser/containers-client.d.ts +3 -3
- package/dist/browser/containers-client.js +76 -76
- package/dist/browser/datasets-client.d.ts +1 -1
- package/dist/browser/datasets-client.js +83 -83
- package/dist/browser/developer-client.d.ts +3 -3
- package/dist/browser/developer-client.js +11 -11
- package/dist/browser/document.d.ts +2 -2
- package/dist/browser/document.js +3 -3
- package/dist/browser/helpers.d.ts +4 -4
- package/dist/browser/helpers.js +9 -9
- package/dist/browser/index.d.ts +35 -35
- package/dist/browser/index.js +35 -35
- package/dist/browser/memory-client.d.ts +1 -1
- package/dist/browser/memory-client.js +6 -6
- package/dist/browser/meshagent-client.d.ts +1 -1
- package/dist/browser/meshagent-client.js +78 -78
- package/dist/browser/messaging-client.d.ts +4 -4
- package/dist/browser/messaging-client.js +33 -33
- package/dist/browser/participant-token.d.ts +1 -1
- package/dist/browser/participant-token.js +5 -5
- package/dist/browser/participant.d.ts +1 -1
- package/dist/browser/protocol.d.ts +7 -4
- package/dist/browser/protocol.js +36 -20
- package/dist/browser/queues-client.d.ts +1 -1
- package/dist/browser/queues-client.js +10 -10
- package/dist/browser/response.js +11 -11
- package/dist/browser/room-client.d.ts +23 -17
- package/dist/browser/room-client.js +138 -130
- package/dist/browser/room-server-client.d.ts +2 -2
- package/dist/browser/room-server-client.js +10 -10
- package/dist/browser/secrets-client.d.ts +3 -3
- package/dist/browser/secrets-client.js +30 -30
- package/dist/browser/services-client.d.ts +2 -2
- package/dist/browser/services-client.js +8 -8
- package/dist/browser/storage-client.d.ts +5 -5
- package/dist/browser/storage-client.js +30 -30
- package/dist/browser/sync-client.d.ts +4 -4
- package/dist/browser/sync-client.js +38 -38
- package/dist/browser/toolkit-config.d.ts +3 -3
- package/dist/esm/agent-client.d.ts +4 -4
- package/dist/esm/agent-client.js +19 -25
- package/dist/esm/agent.d.ts +6 -6
- package/dist/esm/agent.js +73 -93
- package/dist/esm/api_keys.js +12 -21
- package/dist/esm/client.js +7 -13
- package/dist/esm/completer.js +1 -5
- package/dist/esm/containers-client.d.ts +3 -3
- package/dist/esm/containers-client.js +82 -87
- package/dist/esm/datasets-client.d.ts +1 -1
- package/dist/esm/datasets-client.js +101 -111
- package/dist/esm/developer-client.d.ts +3 -3
- package/dist/esm/developer-client.js +11 -15
- package/dist/esm/document.d.ts +2 -2
- package/dist/esm/document.js +11 -20
- package/dist/esm/entrypoint.js +1 -12
- package/dist/esm/event-emitter.js +1 -5
- package/dist/esm/helpers.d.ts +4 -4
- package/dist/esm/helpers.js +15 -23
- package/dist/esm/index.d.ts +35 -35
- package/dist/esm/index.js +35 -51
- package/dist/esm/memory-client.d.ts +1 -1
- package/dist/esm/memory-client.js +7 -11
- package/dist/esm/meshagent-client.d.ts +1 -1
- package/dist/esm/meshagent-client.js +79 -83
- package/dist/esm/messaging-client.d.ts +4 -4
- package/dist/esm/messaging-client.js +33 -37
- package/dist/esm/oauth-scopes.js +2 -5
- package/dist/esm/participant-token.d.ts +1 -1
- package/dist/esm/participant-token.js +34 -62
- package/dist/esm/participant.d.ts +1 -1
- package/dist/esm/participant.js +3 -9
- package/dist/esm/protocol.d.ts +7 -4
- package/dist/esm/protocol.js +48 -46
- package/dist/esm/queues-client.d.ts +1 -1
- package/dist/esm/queues-client.js +12 -17
- package/dist/esm/requirement.js +4 -11
- package/dist/esm/response.js +22 -34
- package/dist/esm/room-client.d.ts +23 -17
- package/dist/esm/room-client.js +140 -137
- package/dist/esm/room-event.js +9 -21
- package/dist/esm/room-server-client.d.ts +2 -2
- package/dist/esm/room-server-client.js +13 -18
- package/dist/esm/runtime.js +1 -10
- package/dist/esm/schema.js +9 -18
- package/dist/esm/secrets-client.d.ts +3 -3
- package/dist/esm/secrets-client.js +31 -35
- package/dist/esm/services-client.d.ts +2 -2
- package/dist/esm/services-client.js +9 -13
- package/dist/esm/storage-client.d.ts +5 -5
- package/dist/esm/storage-client.js +32 -38
- package/dist/esm/stream-controller.js +1 -5
- package/dist/esm/sync-client.d.ts +4 -4
- package/dist/esm/sync-client.js +38 -42
- package/dist/esm/tool-content-type.js +1 -5
- package/dist/esm/toolkit-config.d.ts +3 -3
- package/dist/esm/toolkit-config.js +5 -13
- package/dist/esm/utils.js +10 -20
- package/dist/esm/version.js +1 -4
- package/dist/node/agent-client.d.ts +4 -4
- package/dist/node/agent-client.js +16 -16
- package/dist/node/agent.d.ts +6 -6
- package/dist/node/agent.js +57 -57
- package/dist/node/api_keys.js +7 -3
- package/dist/node/containers-client.d.ts +3 -3
- package/dist/node/containers-client.js +76 -76
- package/dist/node/datasets-client.d.ts +1 -1
- package/dist/node/datasets-client.js +83 -83
- package/dist/node/developer-client.d.ts +3 -3
- package/dist/node/developer-client.js +11 -11
- package/dist/node/document.d.ts +2 -2
- package/dist/node/document.js +3 -3
- package/dist/node/helpers.d.ts +4 -4
- package/dist/node/helpers.js +9 -9
- package/dist/node/index.d.ts +35 -35
- package/dist/node/index.js +35 -35
- package/dist/node/memory-client.d.ts +1 -1
- package/dist/node/memory-client.js +6 -6
- package/dist/node/meshagent-client.d.ts +1 -1
- package/dist/node/meshagent-client.js +78 -78
- package/dist/node/messaging-client.d.ts +4 -4
- package/dist/node/messaging-client.js +33 -33
- package/dist/node/participant-token.d.ts +1 -1
- package/dist/node/participant-token.js +5 -5
- package/dist/node/participant.d.ts +1 -1
- package/dist/node/protocol.d.ts +7 -4
- package/dist/node/protocol.js +36 -20
- package/dist/node/queues-client.d.ts +1 -1
- package/dist/node/queues-client.js +10 -10
- package/dist/node/response.js +11 -11
- package/dist/node/room-client.d.ts +23 -17
- package/dist/node/room-client.js +138 -130
- package/dist/node/room-server-client.d.ts +2 -2
- package/dist/node/room-server-client.js +10 -10
- package/dist/node/secrets-client.d.ts +3 -3
- package/dist/node/secrets-client.js +30 -30
- package/dist/node/services-client.d.ts +2 -2
- package/dist/node/services-client.js +8 -8
- package/dist/node/storage-client.d.ts +5 -5
- package/dist/node/storage-client.js +30 -30
- package/dist/node/sync-client.d.ts +4 -4
- package/dist/node/sync-client.js +38 -38
- package/dist/node/toolkit-config.d.ts +3 -3
- package/package.json +11 -5
- package/dist/browser/lk-client.d.ts +0 -18
- package/dist/browser/lk-client.js +0 -33
- package/dist/browser/lk-protocol.d.ts +0 -22
- package/dist/browser/lk-protocol.js +0 -37
- package/dist/esm/lk-client.d.ts +0 -18
- package/dist/esm/lk-client.js +0 -33
- package/dist/esm/lk-protocol.d.ts +0 -22
- package/dist/esm/lk-protocol.js +0 -37
- package/dist/node/lk-client.d.ts +0 -18
- package/dist/node/lk-client.js +0 -33
- package/dist/node/lk-protocol.d.ts +0 -22
- package/dist/node/lk-protocol.js +0 -37
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const apache_arrow_1 = require("apache-arrow");
|
|
5
|
-
const room_server_client_1 = require("./room-server-client");
|
|
6
|
-
const response_1 = require("./response");
|
|
1
|
+
import { Schema, Table, tableFromIPC, tableToIPC } from "apache-arrow";
|
|
2
|
+
import { RoomServerException } from "./room-server-client.js";
|
|
3
|
+
import { BinaryContent, ControlContent, EmptyContent, ErrorContent, JsonContent } from "./response.js";
|
|
7
4
|
const ARROW_IPC_STREAM_MIME_TYPE = "application/vnd.apache.arrow.stream";
|
|
8
|
-
class DatasetValueEncoder {
|
|
5
|
+
export class DatasetValueEncoder {
|
|
9
6
|
}
|
|
10
|
-
|
|
11
|
-
class DatasetExpression extends DatasetValueEncoder {
|
|
7
|
+
export class DatasetExpression extends DatasetValueEncoder {
|
|
12
8
|
constructor(expression) {
|
|
13
9
|
super();
|
|
14
10
|
const normalized = expression.trim();
|
|
@@ -26,8 +22,7 @@ class DatasetExpression extends DatasetValueEncoder {
|
|
|
26
22
|
return this.expression;
|
|
27
23
|
}
|
|
28
24
|
}
|
|
29
|
-
|
|
30
|
-
class DatasetDate extends DatasetValueEncoder {
|
|
25
|
+
export class DatasetDate extends DatasetValueEncoder {
|
|
31
26
|
constructor(value) {
|
|
32
27
|
super();
|
|
33
28
|
const normalized = value.trim();
|
|
@@ -46,8 +41,7 @@ class DatasetDate extends DatasetValueEncoder {
|
|
|
46
41
|
return this.value;
|
|
47
42
|
}
|
|
48
43
|
}
|
|
49
|
-
|
|
50
|
-
class DatasetStruct extends DatasetValueEncoder {
|
|
44
|
+
export class DatasetStruct extends DatasetValueEncoder {
|
|
51
45
|
constructor(fields) {
|
|
52
46
|
super();
|
|
53
47
|
this.fields = Object.fromEntries(Object.entries(fields).map(([key, value]) => {
|
|
@@ -66,8 +60,7 @@ class DatasetStruct extends DatasetValueEncoder {
|
|
|
66
60
|
};
|
|
67
61
|
}
|
|
68
62
|
}
|
|
69
|
-
|
|
70
|
-
class DatasetJson extends DatasetValueEncoder {
|
|
63
|
+
export class DatasetJson extends DatasetValueEncoder {
|
|
71
64
|
constructor(value) {
|
|
72
65
|
super();
|
|
73
66
|
this.value = normalizeDatasetJsonValue(value);
|
|
@@ -81,14 +74,13 @@ class DatasetJson extends DatasetValueEncoder {
|
|
|
81
74
|
};
|
|
82
75
|
}
|
|
83
76
|
}
|
|
84
|
-
exports.DatasetJson = DatasetJson;
|
|
85
77
|
const globalScope = globalThis;
|
|
86
78
|
const UUID_HEX_REGEX = /^[0-9a-f]{32}$/;
|
|
87
79
|
const ISO_DATE_REGEX = /^\d{4}-\d{2}-\d{2}$/;
|
|
88
80
|
function normalizeUuidHex(value) {
|
|
89
81
|
const normalized = value.trim().toLowerCase().replace(/-/g, "");
|
|
90
82
|
if (!UUID_HEX_REGEX.test(normalized)) {
|
|
91
|
-
throw new
|
|
83
|
+
throw new RoomServerException("invalid uuid format");
|
|
92
84
|
}
|
|
93
85
|
return normalized;
|
|
94
86
|
}
|
|
@@ -99,7 +91,7 @@ function formatUuidHex(value) {
|
|
|
99
91
|
`${value.substring(16, 20)}-` +
|
|
100
92
|
`${value.substring(20)}`);
|
|
101
93
|
}
|
|
102
|
-
class DatasetUuid {
|
|
94
|
+
export class DatasetUuid {
|
|
103
95
|
constructor(value) {
|
|
104
96
|
this.value = formatUuidHex(normalizeUuidHex(value));
|
|
105
97
|
}
|
|
@@ -107,7 +99,6 @@ class DatasetUuid {
|
|
|
107
99
|
return this.value;
|
|
108
100
|
}
|
|
109
101
|
}
|
|
110
|
-
exports.DatasetUuid = DatasetUuid;
|
|
111
102
|
function bytesToBase64(bytes) {
|
|
112
103
|
if (globalScope.Buffer) {
|
|
113
104
|
return globalScope.Buffer.from(bytes).toString("base64");
|
|
@@ -191,7 +182,7 @@ function encodeRecordValue(value) {
|
|
|
191
182
|
};
|
|
192
183
|
}
|
|
193
184
|
if (isRecord(value)) {
|
|
194
|
-
throw new
|
|
185
|
+
throw new RoomServerException("dataset object values must use DatasetStruct or DatasetJson");
|
|
195
186
|
}
|
|
196
187
|
return value;
|
|
197
188
|
}
|
|
@@ -216,62 +207,62 @@ function datasetSqlLiteral(value) {
|
|
|
216
207
|
}
|
|
217
208
|
function decodeRecordValue(value) {
|
|
218
209
|
if (Array.isArray(value)) {
|
|
219
|
-
throw new
|
|
210
|
+
throw new RoomServerException("dataset list values must use a {'list': [...]} wrapper");
|
|
220
211
|
}
|
|
221
212
|
if (!isRecord(value)) {
|
|
222
213
|
return value;
|
|
223
214
|
}
|
|
224
215
|
const entries = Object.entries(value);
|
|
225
216
|
if (entries.length !== 1) {
|
|
226
|
-
throw new
|
|
217
|
+
throw new RoomServerException("dataset object values must use a single-key type wrapper");
|
|
227
218
|
}
|
|
228
219
|
const [wrapper, payload] = entries[0];
|
|
229
220
|
switch (wrapper) {
|
|
230
221
|
case "binary":
|
|
231
222
|
if (typeof payload !== "string") {
|
|
232
|
-
throw new
|
|
223
|
+
throw new RoomServerException("dataset binary values must be base64 strings");
|
|
233
224
|
}
|
|
234
225
|
return base64ToBytes(payload);
|
|
235
226
|
case "uuid":
|
|
236
227
|
if (typeof payload !== "string") {
|
|
237
|
-
throw new
|
|
228
|
+
throw new RoomServerException("dataset uuid values must be strings");
|
|
238
229
|
}
|
|
239
230
|
return new DatasetUuid(payload);
|
|
240
231
|
case "expression":
|
|
241
232
|
if (typeof payload !== "string") {
|
|
242
|
-
throw new
|
|
233
|
+
throw new RoomServerException("dataset expression values must be strings");
|
|
243
234
|
}
|
|
244
235
|
return new DatasetExpression(payload);
|
|
245
236
|
case "date":
|
|
246
237
|
if (typeof payload !== "string") {
|
|
247
|
-
throw new
|
|
238
|
+
throw new RoomServerException("dataset date values must be strings");
|
|
248
239
|
}
|
|
249
240
|
return new DatasetDate(payload);
|
|
250
241
|
case "timestamp":
|
|
251
242
|
if (typeof payload !== "string") {
|
|
252
|
-
throw new
|
|
243
|
+
throw new RoomServerException("dataset timestamp values must be strings");
|
|
253
244
|
}
|
|
254
245
|
{
|
|
255
246
|
const parsed = new Date(payload);
|
|
256
247
|
if (Number.isNaN(parsed.getTime())) {
|
|
257
|
-
throw new
|
|
248
|
+
throw new RoomServerException("dataset timestamp value is not valid");
|
|
258
249
|
}
|
|
259
250
|
return parsed;
|
|
260
251
|
}
|
|
261
252
|
case "list":
|
|
262
253
|
if (!Array.isArray(payload)) {
|
|
263
|
-
throw new
|
|
254
|
+
throw new RoomServerException("dataset list values must be arrays");
|
|
264
255
|
}
|
|
265
256
|
return payload.map((item) => decodeRecordValue(item));
|
|
266
257
|
case "struct":
|
|
267
258
|
if (!isRecord(payload)) {
|
|
268
|
-
throw new
|
|
259
|
+
throw new RoomServerException("dataset struct values must be objects");
|
|
269
260
|
}
|
|
270
261
|
return new DatasetStruct(Object.fromEntries(Object.entries(payload).map(([key, item]) => [key, decodeRecordValue(item)])));
|
|
271
262
|
case "json":
|
|
272
263
|
return new DatasetJson(normalizeDatasetJsonValue(payload));
|
|
273
264
|
default:
|
|
274
|
-
throw new
|
|
265
|
+
throw new RoomServerException(`unsupported dataset value wrapper '${wrapper}'`);
|
|
275
266
|
}
|
|
276
267
|
}
|
|
277
268
|
function encodeDatasetRecord(record) {
|
|
@@ -290,28 +281,28 @@ function rowsChunk(records) {
|
|
|
290
281
|
}
|
|
291
282
|
function recordsFromRowsChunk(payload, operation) {
|
|
292
283
|
if (!isRecord(payload) || payload.kind !== "rows" || !Array.isArray(payload.rows)) {
|
|
293
|
-
throw new
|
|
284
|
+
throw new RoomServerException(`unexpected return type from datasets.${operation}`);
|
|
294
285
|
}
|
|
295
286
|
return payload.rows.map((row) => {
|
|
296
287
|
if (!isRecord(row) || !Array.isArray(row.columns)) {
|
|
297
|
-
throw new
|
|
288
|
+
throw new RoomServerException(`unexpected return type from datasets.${operation}`);
|
|
298
289
|
}
|
|
299
290
|
return Object.fromEntries(row.columns.map((column) => {
|
|
300
291
|
if (!isRecord(column) || typeof column.name !== "string") {
|
|
301
|
-
throw new
|
|
292
|
+
throw new RoomServerException(`unexpected return type from datasets.${operation}`);
|
|
302
293
|
}
|
|
303
294
|
try {
|
|
304
295
|
return [column.name, decodeRecordValue(column.value)];
|
|
305
296
|
}
|
|
306
297
|
catch {
|
|
307
|
-
throw new
|
|
298
|
+
throw new RoomServerException(`unexpected return type from datasets.${operation}`);
|
|
308
299
|
}
|
|
309
300
|
}));
|
|
310
301
|
});
|
|
311
302
|
}
|
|
312
303
|
function rowChunkList(records, rowsPerChunk = 128) {
|
|
313
304
|
if (rowsPerChunk <= 0) {
|
|
314
|
-
throw new
|
|
305
|
+
throw new RoomServerException("rowsPerChunk must be greater than zero");
|
|
315
306
|
}
|
|
316
307
|
const chunks = [];
|
|
317
308
|
for (let index = 0; index < records.length; index += rowsPerChunk) {
|
|
@@ -346,14 +337,14 @@ function normalizeTableRefs(tables) {
|
|
|
346
337
|
}
|
|
347
338
|
function tableIndexFromJson(value) {
|
|
348
339
|
if (!isRecord(value) || typeof value.name !== "string" || typeof value.type !== "string" || !Array.isArray(value.columns)) {
|
|
349
|
-
throw new
|
|
340
|
+
throw new RoomServerException("unexpected return type from datasets.list_indexes");
|
|
350
341
|
}
|
|
351
342
|
return {
|
|
352
343
|
name: value.name,
|
|
353
344
|
type: value.type,
|
|
354
345
|
columns: value.columns.map((column) => {
|
|
355
346
|
if (typeof column !== "string") {
|
|
356
|
-
throw new
|
|
347
|
+
throw new RoomServerException("unexpected return type from datasets.list_indexes");
|
|
357
348
|
}
|
|
358
349
|
return column;
|
|
359
350
|
}),
|
|
@@ -368,7 +359,7 @@ function tableIndexFromJson(value) {
|
|
|
368
359
|
}
|
|
369
360
|
function optimizeResultFromJson(value) {
|
|
370
361
|
if (!isRecord(value)) {
|
|
371
|
-
throw new
|
|
362
|
+
throw new RoomServerException("unexpected return type from datasets.optimize");
|
|
372
363
|
}
|
|
373
364
|
return {
|
|
374
365
|
compaction: typeof value.compaction_json === "string" ? JSON.parse(value.compaction_json) : isRecord(value.compaction) ? value.compaction : null,
|
|
@@ -378,32 +369,32 @@ function optimizeResultFromJson(value) {
|
|
|
378
369
|
}
|
|
379
370
|
function tableStatsFromJson(value) {
|
|
380
371
|
if (!isRecord(value)) {
|
|
381
|
-
throw new
|
|
372
|
+
throw new RoomServerException("unexpected return type from datasets.stats");
|
|
382
373
|
}
|
|
383
374
|
const dataset = typeof value.dataset_json === "string" ? JSON.parse(value.dataset_json) : value.dataset;
|
|
384
375
|
const data = typeof value.data_json === "string" ? JSON.parse(value.data_json) : value.data;
|
|
385
376
|
if (!isRecord(dataset) || !isRecord(data)) {
|
|
386
|
-
throw new
|
|
377
|
+
throw new RoomServerException("unexpected return type from datasets.stats");
|
|
387
378
|
}
|
|
388
379
|
return { dataset, data };
|
|
389
380
|
}
|
|
390
381
|
function tableVersionFromJson(value) {
|
|
391
382
|
if (!isRecord(value) || typeof value.metadata_json !== "string" || typeof value.timestamp !== "string" || typeof value.version !== "number") {
|
|
392
|
-
throw new
|
|
383
|
+
throw new RoomServerException("unexpected return type from datasets.list_versions");
|
|
393
384
|
}
|
|
394
385
|
const timestamp = new Date(value.timestamp);
|
|
395
386
|
if (Number.isNaN(timestamp.getTime())) {
|
|
396
|
-
throw new
|
|
387
|
+
throw new RoomServerException("unexpected return type from datasets.list_versions");
|
|
397
388
|
}
|
|
398
389
|
let metadata;
|
|
399
390
|
try {
|
|
400
391
|
metadata = JSON.parse(value.metadata_json);
|
|
401
392
|
}
|
|
402
393
|
catch (_) {
|
|
403
|
-
throw new
|
|
394
|
+
throw new RoomServerException("unexpected return type from datasets.list_versions");
|
|
404
395
|
}
|
|
405
396
|
if (!isRecord(metadata)) {
|
|
406
|
-
throw new
|
|
397
|
+
throw new RoomServerException("unexpected return type from datasets.list_versions");
|
|
407
398
|
}
|
|
408
399
|
return {
|
|
409
400
|
version: value.version,
|
|
@@ -413,27 +404,27 @@ function tableVersionFromJson(value) {
|
|
|
413
404
|
}
|
|
414
405
|
function tableBranchFromJson(value) {
|
|
415
406
|
if (!isRecord(value) || typeof value.name !== "string") {
|
|
416
|
-
throw new
|
|
407
|
+
throw new RoomServerException("unexpected return type from datasets.list_branches");
|
|
417
408
|
}
|
|
418
409
|
if (value.parent_branch != null && typeof value.parent_branch !== "string") {
|
|
419
|
-
throw new
|
|
410
|
+
throw new RoomServerException("unexpected return type from datasets.list_branches");
|
|
420
411
|
}
|
|
421
412
|
if (value.parent_version != null
|
|
422
413
|
&& (typeof value.parent_version !== "number" || !Number.isInteger(value.parent_version))) {
|
|
423
|
-
throw new
|
|
414
|
+
throw new RoomServerException("unexpected return type from datasets.list_branches");
|
|
424
415
|
}
|
|
425
416
|
if (value.manifest_size != null
|
|
426
417
|
&& (typeof value.manifest_size !== "number" || !Number.isInteger(value.manifest_size))) {
|
|
427
|
-
throw new
|
|
418
|
+
throw new RoomServerException("unexpected return type from datasets.list_branches");
|
|
428
419
|
}
|
|
429
420
|
let createdAt = null;
|
|
430
421
|
if (value.created_at != null) {
|
|
431
422
|
if (typeof value.created_at !== "string") {
|
|
432
|
-
throw new
|
|
423
|
+
throw new RoomServerException("unexpected return type from datasets.list_branches");
|
|
433
424
|
}
|
|
434
425
|
createdAt = new Date(value.created_at);
|
|
435
426
|
if (Number.isNaN(createdAt.getTime())) {
|
|
436
|
-
throw new
|
|
427
|
+
throw new RoomServerException("unexpected return type from datasets.list_branches");
|
|
437
428
|
}
|
|
438
429
|
}
|
|
439
430
|
return {
|
|
@@ -499,7 +490,7 @@ class DatasetWriteInputStream {
|
|
|
499
490
|
});
|
|
500
491
|
}
|
|
501
492
|
async *stream() {
|
|
502
|
-
yield new
|
|
493
|
+
yield new JsonContent({ json: this.start });
|
|
503
494
|
while (!this.closed) {
|
|
504
495
|
await this.waitForPull();
|
|
505
496
|
if (this.closed) {
|
|
@@ -512,7 +503,7 @@ class DatasetWriteInputStream {
|
|
|
512
503
|
if (nextChunk.value.length === 0) {
|
|
513
504
|
continue;
|
|
514
505
|
}
|
|
515
|
-
yield new
|
|
506
|
+
yield new JsonContent({ json: rowsChunk(nextChunk.value) });
|
|
516
507
|
}
|
|
517
508
|
}
|
|
518
509
|
}
|
|
@@ -528,18 +519,18 @@ async function* toAsyncArrowIterable(chunks) {
|
|
|
528
519
|
}
|
|
529
520
|
}
|
|
530
521
|
function schemaToIPC(schema) {
|
|
531
|
-
return
|
|
522
|
+
return tableToIPC(new Table(schema, []), "stream");
|
|
532
523
|
}
|
|
533
524
|
function tableFromIPCBytes(data) {
|
|
534
|
-
const table =
|
|
525
|
+
const table = tableFromIPC(data);
|
|
535
526
|
if (table instanceof Promise) {
|
|
536
|
-
throw new
|
|
527
|
+
throw new RoomServerException("unexpected async Arrow IPC result");
|
|
537
528
|
}
|
|
538
529
|
return table;
|
|
539
530
|
}
|
|
540
531
|
function tableFromChunks(chunks) {
|
|
541
532
|
if (chunks.length === 0) {
|
|
542
|
-
return new
|
|
533
|
+
return new Table(new Schema([]), []);
|
|
543
534
|
}
|
|
544
535
|
const [first, ...rest] = chunks;
|
|
545
536
|
return first.concat(...rest);
|
|
@@ -591,7 +582,7 @@ class DatasetArrowWriteInputStream {
|
|
|
591
582
|
});
|
|
592
583
|
}
|
|
593
584
|
async *stream() {
|
|
594
|
-
yield new
|
|
585
|
+
yield new BinaryContent({
|
|
595
586
|
data: this.schema == null ? new Uint8Array() : schemaToIPC(this.schema),
|
|
596
587
|
headers: this.start,
|
|
597
588
|
});
|
|
@@ -607,8 +598,8 @@ class DatasetArrowWriteInputStream {
|
|
|
607
598
|
if (nextChunk.value.numRows === 0) {
|
|
608
599
|
continue;
|
|
609
600
|
}
|
|
610
|
-
yield new
|
|
611
|
-
data:
|
|
601
|
+
yield new BinaryContent({
|
|
602
|
+
data: tableToIPC(nextChunk.value, "stream"),
|
|
612
603
|
headers: { kind: "data", content_type: ARROW_IPC_STREAM_MIME_TYPE },
|
|
613
604
|
});
|
|
614
605
|
}
|
|
@@ -655,13 +646,13 @@ class DatasetReadInputStream {
|
|
|
655
646
|
});
|
|
656
647
|
}
|
|
657
648
|
async *stream() {
|
|
658
|
-
yield new
|
|
649
|
+
yield new JsonContent({ json: this.start });
|
|
659
650
|
while (!this.closed) {
|
|
660
651
|
await this.waitForPull();
|
|
661
652
|
if (this.closed) {
|
|
662
653
|
return;
|
|
663
654
|
}
|
|
664
|
-
yield new
|
|
655
|
+
yield new JsonContent({ json: { kind: "pull" } });
|
|
665
656
|
}
|
|
666
657
|
}
|
|
667
658
|
}
|
|
@@ -706,26 +697,26 @@ class DatasetArrowReadInputStream {
|
|
|
706
697
|
});
|
|
707
698
|
}
|
|
708
699
|
async *stream() {
|
|
709
|
-
yield new
|
|
700
|
+
yield new BinaryContent({ data: new Uint8Array(), headers: this.start });
|
|
710
701
|
while (!this.closed) {
|
|
711
702
|
await this.waitForPull();
|
|
712
703
|
if (this.closed) {
|
|
713
704
|
return;
|
|
714
705
|
}
|
|
715
|
-
yield new
|
|
706
|
+
yield new BinaryContent({ data: new Uint8Array(), headers: { kind: "pull" } });
|
|
716
707
|
}
|
|
717
708
|
}
|
|
718
709
|
}
|
|
719
|
-
class DatasetsClient {
|
|
710
|
+
export class DatasetsClient {
|
|
720
711
|
constructor({ room }) {
|
|
721
712
|
this.room = room;
|
|
722
713
|
}
|
|
723
714
|
_unexpectedResponseError(operation) {
|
|
724
|
-
return new
|
|
715
|
+
return new RoomServerException(`unexpected return type from datasets.${operation}`);
|
|
725
716
|
}
|
|
726
717
|
async invoke(operation, input) {
|
|
727
718
|
const response = await this.room.invoke({ toolkit: "dataset", tool: operation, input });
|
|
728
|
-
if (response instanceof
|
|
719
|
+
if (response instanceof JsonContent) {
|
|
729
720
|
return response;
|
|
730
721
|
}
|
|
731
722
|
if (response == null) {
|
|
@@ -743,23 +734,23 @@ class DatasetsClient {
|
|
|
743
734
|
const response = await this.invokeStream(operation, input.stream());
|
|
744
735
|
try {
|
|
745
736
|
for await (const chunk of response) {
|
|
746
|
-
if (chunk instanceof
|
|
747
|
-
throw new
|
|
737
|
+
if (chunk instanceof ErrorContent) {
|
|
738
|
+
throw new RoomServerException(chunk.text, chunk.code);
|
|
748
739
|
}
|
|
749
|
-
if (chunk instanceof
|
|
740
|
+
if (chunk instanceof ControlContent) {
|
|
750
741
|
if (chunk.method === "close") {
|
|
751
742
|
return;
|
|
752
743
|
}
|
|
753
744
|
throw this._unexpectedResponseError(operation);
|
|
754
745
|
}
|
|
755
|
-
if (chunk instanceof
|
|
746
|
+
if (chunk instanceof BinaryContent) {
|
|
756
747
|
if (chunk.headers.kind !== "pull") {
|
|
757
748
|
throw this._unexpectedResponseError(operation);
|
|
758
749
|
}
|
|
759
750
|
input.requestNext();
|
|
760
751
|
continue;
|
|
761
752
|
}
|
|
762
|
-
if (!(chunk instanceof
|
|
753
|
+
if (!(chunk instanceof JsonContent) || chunk.json.kind !== "pull") {
|
|
763
754
|
throw this._unexpectedResponseError(operation);
|
|
764
755
|
}
|
|
765
756
|
input.requestNext();
|
|
@@ -775,16 +766,16 @@ class DatasetsClient {
|
|
|
775
766
|
input.requestNext();
|
|
776
767
|
try {
|
|
777
768
|
for await (const chunk of response) {
|
|
778
|
-
if (chunk instanceof
|
|
779
|
-
throw new
|
|
769
|
+
if (chunk instanceof ErrorContent) {
|
|
770
|
+
throw new RoomServerException(chunk.text, chunk.code);
|
|
780
771
|
}
|
|
781
|
-
if (chunk instanceof
|
|
772
|
+
if (chunk instanceof ControlContent) {
|
|
782
773
|
if (chunk.method === "close") {
|
|
783
774
|
return;
|
|
784
775
|
}
|
|
785
776
|
throw this._unexpectedResponseError(operation);
|
|
786
777
|
}
|
|
787
|
-
if (!(chunk instanceof
|
|
778
|
+
if (!(chunk instanceof JsonContent)) {
|
|
788
779
|
throw this._unexpectedResponseError(operation);
|
|
789
780
|
}
|
|
790
781
|
yield recordsFromRowsChunk(chunk.json, operation);
|
|
@@ -801,16 +792,16 @@ class DatasetsClient {
|
|
|
801
792
|
input.requestNext();
|
|
802
793
|
try {
|
|
803
794
|
for await (const chunk of response) {
|
|
804
|
-
if (chunk instanceof
|
|
805
|
-
throw new
|
|
795
|
+
if (chunk instanceof ErrorContent) {
|
|
796
|
+
throw new RoomServerException(chunk.text, chunk.code);
|
|
806
797
|
}
|
|
807
|
-
if (chunk instanceof
|
|
798
|
+
if (chunk instanceof ControlContent) {
|
|
808
799
|
if (chunk.method === "close") {
|
|
809
800
|
return;
|
|
810
801
|
}
|
|
811
802
|
throw this._unexpectedResponseError(operation);
|
|
812
803
|
}
|
|
813
|
-
if (!(chunk instanceof
|
|
804
|
+
if (!(chunk instanceof BinaryContent) || chunk.headers.kind !== "data") {
|
|
814
805
|
throw this._unexpectedResponseError(operation);
|
|
815
806
|
}
|
|
816
807
|
yield tableFromIPCBytes(chunk.data);
|
|
@@ -826,7 +817,7 @@ class DatasetsClient {
|
|
|
826
817
|
namespace: namespace ?? null,
|
|
827
818
|
branch: branch ?? null,
|
|
828
819
|
});
|
|
829
|
-
if (!(response instanceof
|
|
820
|
+
if (!(response instanceof JsonContent)) {
|
|
830
821
|
throw this._unexpectedResponseError("list_tables");
|
|
831
822
|
}
|
|
832
823
|
return Array.isArray(response.json.tables) ? response.json.tables : [];
|
|
@@ -846,7 +837,7 @@ class DatasetsClient {
|
|
|
846
837
|
return this.createTable({
|
|
847
838
|
name,
|
|
848
839
|
schema,
|
|
849
|
-
data: data == null ? undefined : data instanceof
|
|
840
|
+
data: data == null ? undefined : data instanceof Table ? [data] : data,
|
|
850
841
|
mode,
|
|
851
842
|
namespace,
|
|
852
843
|
branch,
|
|
@@ -888,7 +879,7 @@ class DatasetsClient {
|
|
|
888
879
|
async createTableFromData({ name, data, mode = "create", namespace, branch, metadata }) {
|
|
889
880
|
return this.createTable({
|
|
890
881
|
name,
|
|
891
|
-
data: data == null ? undefined : data instanceof
|
|
882
|
+
data: data == null ? undefined : data instanceof Table ? [data] : data,
|
|
892
883
|
mode,
|
|
893
884
|
namespace,
|
|
894
885
|
branch,
|
|
@@ -972,8 +963,8 @@ class DatasetsClient {
|
|
|
972
963
|
});
|
|
973
964
|
}
|
|
974
965
|
async addColumns({ table, newColumns, namespace, branch }) {
|
|
975
|
-
if (newColumns instanceof
|
|
976
|
-
await this.invokeContent("add_columns", new
|
|
966
|
+
if (newColumns instanceof Schema) {
|
|
967
|
+
await this.invokeContent("add_columns", new BinaryContent({
|
|
977
968
|
data: schemaToIPC(newColumns),
|
|
978
969
|
headers: {
|
|
979
970
|
table,
|
|
@@ -1064,8 +1055,8 @@ class DatasetsClient {
|
|
|
1064
1055
|
return tableFromChunks(await this.sql({ query, tables, params, namespace, branch }));
|
|
1065
1056
|
}
|
|
1066
1057
|
async openSqlQuery({ query, tables, params, namespace, branch }) {
|
|
1067
|
-
const response = await this.invokeContent("open_sql_query", new
|
|
1068
|
-
data: params == null ? new Uint8Array() :
|
|
1058
|
+
const response = await this.invokeContent("open_sql_query", new BinaryContent({
|
|
1059
|
+
data: params == null ? new Uint8Array() : tableToIPC(params, "stream"),
|
|
1069
1060
|
headers: {
|
|
1070
1061
|
query,
|
|
1071
1062
|
tables: normalizeTableRefs(tables ?? []),
|
|
@@ -1073,7 +1064,7 @@ class DatasetsClient {
|
|
|
1073
1064
|
branch: branch ?? null,
|
|
1074
1065
|
},
|
|
1075
1066
|
}));
|
|
1076
|
-
if (!(response instanceof
|
|
1067
|
+
if (!(response instanceof BinaryContent)) {
|
|
1077
1068
|
throw this._unexpectedResponseError("open_sql_query");
|
|
1078
1069
|
}
|
|
1079
1070
|
const queryId = response.headers.query_id;
|
|
@@ -1087,8 +1078,8 @@ class DatasetsClient {
|
|
|
1087
1078
|
};
|
|
1088
1079
|
}
|
|
1089
1080
|
async executeSql({ query, tables, params, namespace, branch }) {
|
|
1090
|
-
const response = await this.invokeContent("execute_sql", new
|
|
1091
|
-
data: params == null ? new Uint8Array() :
|
|
1081
|
+
const response = await this.invokeContent("execute_sql", new BinaryContent({
|
|
1082
|
+
data: params == null ? new Uint8Array() : tableToIPC(params, "stream"),
|
|
1092
1083
|
headers: {
|
|
1093
1084
|
query,
|
|
1094
1085
|
tables: normalizeTableRefs(tables ?? []),
|
|
@@ -1096,7 +1087,7 @@ class DatasetsClient {
|
|
|
1096
1087
|
branch: branch ?? null,
|
|
1097
1088
|
},
|
|
1098
1089
|
}));
|
|
1099
|
-
if (response instanceof
|
|
1090
|
+
if (response instanceof BinaryContent) {
|
|
1100
1091
|
if (response.headers.kind !== "query") {
|
|
1101
1092
|
throw this._unexpectedResponseError("execute_sql");
|
|
1102
1093
|
}
|
|
@@ -1110,7 +1101,7 @@ class DatasetsClient {
|
|
|
1110
1101
|
queryId,
|
|
1111
1102
|
};
|
|
1112
1103
|
}
|
|
1113
|
-
if (response instanceof
|
|
1104
|
+
if (response instanceof JsonContent) {
|
|
1114
1105
|
if (response.json.kind !== "statement"
|
|
1115
1106
|
|| typeof response.json.rows_affected !== "number"
|
|
1116
1107
|
|| !Number.isInteger(response.json.rows_affected)) {
|
|
@@ -1126,7 +1117,7 @@ class DatasetsClient {
|
|
|
1126
1117
|
async *sqlStream({ query, tables, params, namespace, branch }) {
|
|
1127
1118
|
const result = await this.executeSql({ query, tables, params, namespace, branch });
|
|
1128
1119
|
if (result.kind === "statement") {
|
|
1129
|
-
throw new
|
|
1120
|
+
throw new RoomServerException(`SQL statement did not return rows; rows_affected=${result.rowsAffected}`);
|
|
1130
1121
|
}
|
|
1131
1122
|
const opened = result;
|
|
1132
1123
|
try {
|
|
@@ -1144,21 +1135,21 @@ class DatasetsClient {
|
|
|
1144
1135
|
}
|
|
1145
1136
|
async closeSqlQuery({ queryId }) {
|
|
1146
1137
|
const response = await this.room.invoke({ toolkit: "dataset", tool: "close_sql_query", input: { query_id: queryId } });
|
|
1147
|
-
if (!(response instanceof
|
|
1138
|
+
if (!(response instanceof EmptyContent)) {
|
|
1148
1139
|
throw this._unexpectedResponseError("close_sql_query");
|
|
1149
1140
|
}
|
|
1150
1141
|
}
|
|
1151
1142
|
async cancelSqlQuery({ queryId }) {
|
|
1152
1143
|
const response = await this.room.invoke({ toolkit: "dataset", tool: "cancel_sql_query", input: { query_id: queryId } });
|
|
1153
|
-
if (!(response instanceof
|
|
1144
|
+
if (!(response instanceof JsonContent)
|
|
1154
1145
|
|| !["cancelled", "cancelling", "not_cancellable"].includes(response.json.status)) {
|
|
1155
1146
|
throw this._unexpectedResponseError("cancel_sql_query");
|
|
1156
1147
|
}
|
|
1157
1148
|
return { status: response.json.status };
|
|
1158
1149
|
}
|
|
1159
1150
|
async executeSqlStatement({ query, tables, params, namespace, branch }) {
|
|
1160
|
-
const response = await this.invokeContent("execute_sql_statement", new
|
|
1161
|
-
data: params == null ? new Uint8Array() :
|
|
1151
|
+
const response = await this.invokeContent("execute_sql_statement", new BinaryContent({
|
|
1152
|
+
data: params == null ? new Uint8Array() : tableToIPC(params, "stream"),
|
|
1162
1153
|
headers: {
|
|
1163
1154
|
query,
|
|
1164
1155
|
tables: normalizeTableRefs(tables ?? []),
|
|
@@ -1166,7 +1157,7 @@ class DatasetsClient {
|
|
|
1166
1157
|
branch: branch ?? null,
|
|
1167
1158
|
},
|
|
1168
1159
|
}));
|
|
1169
|
-
if (!(response instanceof
|
|
1160
|
+
if (!(response instanceof JsonContent)
|
|
1170
1161
|
|| typeof response.json.rows_affected !== "number"
|
|
1171
1162
|
|| !Number.isInteger(response.json.rows_affected)) {
|
|
1172
1163
|
throw this._unexpectedResponseError("execute_sql_statement");
|
|
@@ -1233,16 +1224,16 @@ class DatasetsClient {
|
|
|
1233
1224
|
input.requestNext();
|
|
1234
1225
|
try {
|
|
1235
1226
|
for await (const chunk of response) {
|
|
1236
|
-
if (chunk instanceof
|
|
1237
|
-
throw new
|
|
1227
|
+
if (chunk instanceof ErrorContent) {
|
|
1228
|
+
throw new RoomServerException(chunk.text, chunk.code);
|
|
1238
1229
|
}
|
|
1239
|
-
if (chunk instanceof
|
|
1230
|
+
if (chunk instanceof ControlContent) {
|
|
1240
1231
|
if (chunk.method === "close") {
|
|
1241
1232
|
return;
|
|
1242
1233
|
}
|
|
1243
1234
|
throw this._unexpectedResponseError("watch_table");
|
|
1244
1235
|
}
|
|
1245
|
-
if (chunk instanceof
|
|
1236
|
+
if (chunk instanceof BinaryContent) {
|
|
1246
1237
|
if (chunk.headers.kind !== "data") {
|
|
1247
1238
|
throw this._unexpectedResponseError("watch_table");
|
|
1248
1239
|
}
|
|
@@ -1260,7 +1251,7 @@ class DatasetsClient {
|
|
|
1260
1251
|
input.requestNext();
|
|
1261
1252
|
continue;
|
|
1262
1253
|
}
|
|
1263
|
-
if (chunk instanceof
|
|
1254
|
+
if (chunk instanceof JsonContent) {
|
|
1264
1255
|
if (!isRecord(chunk.json)) {
|
|
1265
1256
|
throw this._unexpectedResponseError("watch_table");
|
|
1266
1257
|
}
|
|
@@ -1299,7 +1290,7 @@ class DatasetsClient {
|
|
|
1299
1290
|
branch: branch ?? null,
|
|
1300
1291
|
version: version ?? null,
|
|
1301
1292
|
});
|
|
1302
|
-
if (!(response instanceof
|
|
1293
|
+
if (!(response instanceof JsonContent) || typeof response.json.count !== "number" || !Number.isInteger(response.json.count)) {
|
|
1303
1294
|
throw this._unexpectedResponseError("count");
|
|
1304
1295
|
}
|
|
1305
1296
|
return response.json.count;
|
|
@@ -1315,7 +1306,7 @@ class DatasetsClient {
|
|
|
1315
1306
|
version: version ?? null,
|
|
1316
1307
|
},
|
|
1317
1308
|
});
|
|
1318
|
-
if (!(response instanceof
|
|
1309
|
+
if (!(response instanceof BinaryContent)) {
|
|
1319
1310
|
throw this._unexpectedResponseError("inspect");
|
|
1320
1311
|
}
|
|
1321
1312
|
return tableFromIPCBytes(response.data).schema;
|
|
@@ -1331,7 +1322,7 @@ class DatasetsClient {
|
|
|
1331
1322
|
branch: branch ?? null,
|
|
1332
1323
|
config: config ?? null,
|
|
1333
1324
|
});
|
|
1334
|
-
if (!(response instanceof
|
|
1325
|
+
if (!(response instanceof JsonContent)) {
|
|
1335
1326
|
throw this._unexpectedResponseError("optimize");
|
|
1336
1327
|
}
|
|
1337
1328
|
return optimizeResultFromJson(response.json);
|
|
@@ -1344,7 +1335,7 @@ class DatasetsClient {
|
|
|
1344
1335
|
version: version ?? null,
|
|
1345
1336
|
max_rows_per_group: maxRowsPerGroup ?? null,
|
|
1346
1337
|
});
|
|
1347
|
-
if (!(response instanceof
|
|
1338
|
+
if (!(response instanceof JsonContent)) {
|
|
1348
1339
|
throw this._unexpectedResponseError("stats");
|
|
1349
1340
|
}
|
|
1350
1341
|
return tableStatsFromJson(response.json);
|
|
@@ -1362,7 +1353,7 @@ class DatasetsClient {
|
|
|
1362
1353
|
namespace: namespace ?? null,
|
|
1363
1354
|
branch: branch ?? null,
|
|
1364
1355
|
});
|
|
1365
|
-
if (!(response instanceof
|
|
1356
|
+
if (!(response instanceof JsonContent) || !Array.isArray(response.json.versions)) {
|
|
1366
1357
|
throw this._unexpectedResponseError("list_versions");
|
|
1367
1358
|
}
|
|
1368
1359
|
return response.json.versions.map((version) => tableVersionFromJson(version));
|
|
@@ -1381,7 +1372,7 @@ class DatasetsClient {
|
|
|
1381
1372
|
branch: branch ?? null,
|
|
1382
1373
|
version: version ?? null,
|
|
1383
1374
|
});
|
|
1384
|
-
if (!(response instanceof
|
|
1375
|
+
if (!(response instanceof JsonContent) || !Array.isArray(response.json.indexes)) {
|
|
1385
1376
|
throw this._unexpectedResponseError("list_indexes");
|
|
1386
1377
|
}
|
|
1387
1378
|
return response.json.indexes.map((index) => tableIndexFromJson(index));
|
|
@@ -1390,7 +1381,7 @@ class DatasetsClient {
|
|
|
1390
1381
|
const response = await this.invoke("list_branches", {
|
|
1391
1382
|
namespace: namespace ?? null,
|
|
1392
1383
|
});
|
|
1393
|
-
if (!(response instanceof
|
|
1384
|
+
if (!(response instanceof JsonContent) || !Array.isArray(response.json.branches)) {
|
|
1394
1385
|
throw this._unexpectedResponseError("list_branches");
|
|
1395
1386
|
}
|
|
1396
1387
|
return response.json.branches.map((branch) => tableBranchFromJson(branch));
|
|
@@ -1414,4 +1405,3 @@ class DatasetsClient {
|
|
|
1414
1405
|
});
|
|
1415
1406
|
}
|
|
1416
1407
|
}
|
|
1417
|
-
exports.DatasetsClient = DatasetsClient;
|