@meshagent/meshagent 0.35.5 → 0.35.7
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 +16 -0
- package/dist/browser/containers-client.d.ts +79 -2
- package/dist/browser/containers-client.js +341 -19
- package/dist/browser/database-client.d.ts +95 -24
- package/dist/browser/database-client.js +150 -49
- package/dist/browser/messaging-client.d.ts +33 -52
- package/dist/browser/messaging-client.js +180 -184
- package/dist/browser/participant.d.ts +5 -3
- package/dist/browser/participant.js +9 -1
- package/dist/browser/room-client.js +2 -0
- package/dist/browser/room-event.d.ts +6 -2
- package/dist/browser/room-event.js +4 -2
- package/dist/browser/secrets-client.d.ts +86 -16
- package/dist/browser/secrets-client.js +243 -44
- package/dist/browser/storage-client.d.ts +17 -4
- package/dist/browser/storage-client.js +141 -30
- package/dist/esm/containers-client.d.ts +79 -2
- package/dist/esm/containers-client.js +341 -19
- package/dist/esm/database-client.d.ts +95 -24
- package/dist/esm/database-client.js +150 -49
- package/dist/esm/messaging-client.d.ts +33 -52
- package/dist/esm/messaging-client.js +179 -180
- package/dist/esm/participant.d.ts +5 -3
- package/dist/esm/participant.js +9 -1
- package/dist/esm/room-client.js +2 -0
- package/dist/esm/room-event.d.ts +6 -2
- package/dist/esm/room-event.js +4 -2
- package/dist/esm/secrets-client.d.ts +86 -16
- package/dist/esm/secrets-client.js +243 -44
- package/dist/esm/storage-client.d.ts +17 -4
- package/dist/esm/storage-client.js +140 -30
- package/dist/node/containers-client.d.ts +79 -2
- package/dist/node/containers-client.js +341 -19
- package/dist/node/database-client.d.ts +95 -24
- package/dist/node/database-client.js +150 -49
- package/dist/node/messaging-client.d.ts +33 -52
- package/dist/node/messaging-client.js +180 -184
- package/dist/node/participant.d.ts +5 -3
- package/dist/node/participant.js +9 -1
- package/dist/node/room-client.js +2 -0
- package/dist/node/room-event.d.ts +6 -2
- package/dist/node/room-event.js +4 -2
- package/dist/node/secrets-client.d.ts +86 -16
- package/dist/node/secrets-client.js +243 -44
- package/dist/node/storage-client.d.ts +17 -4
- package/dist/node/storage-client.js +141 -30
- package/package.json +1 -1
|
@@ -6,118 +6,189 @@ export interface TableRef {
|
|
|
6
6
|
namespace?: string[];
|
|
7
7
|
alias?: string;
|
|
8
8
|
}
|
|
9
|
+
export interface TableVersion {
|
|
10
|
+
version: number;
|
|
11
|
+
timestamp: Date;
|
|
12
|
+
metadata: Record<string, unknown>;
|
|
13
|
+
}
|
|
14
|
+
export interface TableIndex {
|
|
15
|
+
name: string;
|
|
16
|
+
columns: string[];
|
|
17
|
+
type: string;
|
|
18
|
+
}
|
|
19
|
+
type DatabaseRoomInvoker = Pick<RoomClient, "invoke" | "invokeStream">;
|
|
9
20
|
export declare class DatabaseClient {
|
|
10
21
|
private room;
|
|
11
22
|
constructor({ room }: {
|
|
12
|
-
room:
|
|
23
|
+
room: DatabaseRoomInvoker;
|
|
13
24
|
});
|
|
14
25
|
private _unexpectedResponseError;
|
|
15
26
|
private invoke;
|
|
16
27
|
private invokeStream;
|
|
17
28
|
private drainWriteStream;
|
|
18
29
|
private streamRows;
|
|
19
|
-
listTables(
|
|
30
|
+
listTables({ namespace }?: {
|
|
31
|
+
namespace?: string[];
|
|
32
|
+
}): Promise<string[]>;
|
|
20
33
|
private createTable;
|
|
21
|
-
createTableWithSchema({ name, schema, data, mode }: {
|
|
34
|
+
createTableWithSchema({ name, schema, data, mode, namespace, metadata }: {
|
|
22
35
|
name: string;
|
|
23
36
|
schema?: Record<string, DataType>;
|
|
24
37
|
data?: Array<Record<string, any>>;
|
|
25
38
|
mode?: CreateMode;
|
|
39
|
+
namespace?: string[];
|
|
40
|
+
metadata?: Record<string, unknown>;
|
|
26
41
|
}): Promise<void>;
|
|
27
|
-
createTableFromData({ name, data, mode }: {
|
|
42
|
+
createTableFromData({ name, data, mode, namespace, metadata }: {
|
|
28
43
|
name: string;
|
|
29
44
|
data?: Array<Record<string, any>>;
|
|
30
45
|
mode?: CreateMode;
|
|
46
|
+
namespace?: string[];
|
|
47
|
+
metadata?: Record<string, unknown>;
|
|
31
48
|
}): Promise<void>;
|
|
32
|
-
createTableFromDataStream({ name, chunks, schema, mode }: {
|
|
49
|
+
createTableFromDataStream({ name, chunks, schema, mode, namespace, metadata }: {
|
|
33
50
|
name: string;
|
|
34
51
|
chunks: AsyncIterable<Array<Record<string, any>>> | Iterable<Array<Record<string, any>>>;
|
|
35
52
|
schema?: Record<string, DataType>;
|
|
36
53
|
mode?: CreateMode;
|
|
54
|
+
namespace?: string[];
|
|
55
|
+
metadata?: Record<string, unknown>;
|
|
37
56
|
}): Promise<void>;
|
|
38
|
-
dropTable({ name, ignoreMissing }: {
|
|
57
|
+
dropTable({ name, ignoreMissing, namespace }: {
|
|
39
58
|
name: string;
|
|
40
59
|
ignoreMissing?: boolean;
|
|
60
|
+
namespace?: string[];
|
|
61
|
+
}): Promise<void>;
|
|
62
|
+
dropIndex({ table, name, namespace }: {
|
|
63
|
+
table: string;
|
|
64
|
+
name: string;
|
|
65
|
+
namespace?: string[];
|
|
41
66
|
}): Promise<void>;
|
|
42
|
-
addColumns({ table, newColumns }: {
|
|
67
|
+
addColumns({ table, newColumns, namespace }: {
|
|
43
68
|
table: string;
|
|
44
|
-
newColumns: Record<string, string>;
|
|
69
|
+
newColumns: Record<string, string | DataType>;
|
|
70
|
+
namespace?: string[];
|
|
45
71
|
}): Promise<void>;
|
|
46
|
-
dropColumns({ table, columns }: {
|
|
72
|
+
dropColumns({ table, columns, namespace }: {
|
|
47
73
|
table: string;
|
|
48
74
|
columns: string[];
|
|
75
|
+
namespace?: string[];
|
|
49
76
|
}): Promise<void>;
|
|
50
|
-
insert({ table, records }: {
|
|
77
|
+
insert({ table, records, namespace }: {
|
|
51
78
|
table: string;
|
|
52
79
|
records: Array<Record<string, any>>;
|
|
80
|
+
namespace?: string[];
|
|
53
81
|
}): Promise<void>;
|
|
54
|
-
insertStream({ table, chunks }: {
|
|
82
|
+
insertStream({ table, chunks, namespace }: {
|
|
55
83
|
table: string;
|
|
56
84
|
chunks: AsyncIterable<Array<Record<string, any>>> | Iterable<Array<Record<string, any>>>;
|
|
85
|
+
namespace?: string[];
|
|
57
86
|
}): Promise<void>;
|
|
58
|
-
update({ table, where, values, valuesSql }: {
|
|
87
|
+
update({ table, where, values, valuesSql, namespace }: {
|
|
59
88
|
table: string;
|
|
60
89
|
where: string;
|
|
61
90
|
values?: Record<string, any>;
|
|
62
91
|
valuesSql?: Record<string, string>;
|
|
92
|
+
namespace?: string[];
|
|
63
93
|
}): Promise<void>;
|
|
64
|
-
delete({ table, where }: {
|
|
94
|
+
delete({ table, where, namespace }: {
|
|
65
95
|
table: string;
|
|
66
96
|
where: string;
|
|
97
|
+
namespace?: string[];
|
|
67
98
|
}): Promise<void>;
|
|
68
|
-
merge({ table, on, records }: {
|
|
99
|
+
merge({ table, on, records, namespace }: {
|
|
69
100
|
table: string;
|
|
70
101
|
on: string;
|
|
71
102
|
records: Array<Record<string, any>>;
|
|
103
|
+
namespace?: string[];
|
|
72
104
|
}): Promise<void>;
|
|
73
|
-
mergeStream({ table, on, chunks }: {
|
|
105
|
+
mergeStream({ table, on, chunks, namespace }: {
|
|
74
106
|
table: string;
|
|
75
107
|
on: string;
|
|
76
108
|
chunks: AsyncIterable<Array<Record<string, any>>> | Iterable<Array<Record<string, any>>>;
|
|
109
|
+
namespace?: string[];
|
|
77
110
|
}): Promise<void>;
|
|
78
111
|
sql({ query, tables, params }: {
|
|
79
112
|
query: string;
|
|
80
|
-
tables: TableRef
|
|
113
|
+
tables: Array<TableRef | string>;
|
|
81
114
|
params?: Record<string, any>;
|
|
82
115
|
}): Promise<Array<Record<string, any>>>;
|
|
83
116
|
sqlStream({ query, tables, params }: {
|
|
84
117
|
query: string;
|
|
85
|
-
tables: TableRef
|
|
118
|
+
tables: Array<TableRef | string>;
|
|
86
119
|
params?: Record<string, any>;
|
|
87
120
|
}): AsyncIterable<Array<Record<string, any>>>;
|
|
88
|
-
search({ table, text, vector, where, limit, select }: {
|
|
121
|
+
search({ table, text, vector, where, offset, limit, select, namespace }: {
|
|
89
122
|
table: string;
|
|
90
123
|
text?: string;
|
|
91
124
|
vector?: number[];
|
|
92
125
|
where?: string | Record<string, any>;
|
|
126
|
+
offset?: number;
|
|
93
127
|
limit?: number;
|
|
94
128
|
select?: string[];
|
|
129
|
+
namespace?: string[];
|
|
95
130
|
}): Promise<Array<Record<string, any>>>;
|
|
96
|
-
searchStream({ table, text, vector, where, limit, select }: {
|
|
131
|
+
searchStream({ table, text, vector, where, offset, limit, select, namespace }: {
|
|
97
132
|
table: string;
|
|
98
133
|
text?: string;
|
|
99
134
|
vector?: number[];
|
|
100
135
|
where?: string | Record<string, any>;
|
|
136
|
+
offset?: number;
|
|
101
137
|
limit?: number;
|
|
102
138
|
select?: string[];
|
|
139
|
+
namespace?: string[];
|
|
103
140
|
}): AsyncIterable<Array<Record<string, any>>>;
|
|
141
|
+
count({ table, text, vector, where, namespace }: {
|
|
142
|
+
table: string;
|
|
143
|
+
text?: string;
|
|
144
|
+
vector?: number[];
|
|
145
|
+
where?: string | Record<string, any>;
|
|
146
|
+
namespace?: string[];
|
|
147
|
+
}): Promise<number>;
|
|
148
|
+
inspect({ table, namespace }: {
|
|
149
|
+
table: string;
|
|
150
|
+
namespace?: string[];
|
|
151
|
+
}): Promise<Record<string, DataType>>;
|
|
104
152
|
optimize(table: string): Promise<void>;
|
|
105
|
-
|
|
153
|
+
optimize(params: {
|
|
154
|
+
table: string;
|
|
155
|
+
namespace?: string[];
|
|
156
|
+
}): Promise<void>;
|
|
157
|
+
restore({ table, version, namespace }: {
|
|
158
|
+
table: string;
|
|
159
|
+
version: number;
|
|
160
|
+
namespace?: string[];
|
|
161
|
+
}): Promise<void>;
|
|
162
|
+
checkout({ table, version, namespace }: {
|
|
163
|
+
table: string;
|
|
164
|
+
version: number;
|
|
165
|
+
namespace?: string[];
|
|
166
|
+
}): Promise<void>;
|
|
167
|
+
listVersions({ table, namespace }: {
|
|
168
|
+
table: string;
|
|
169
|
+
namespace?: string[];
|
|
170
|
+
}): Promise<TableVersion[]>;
|
|
171
|
+
createVectorIndex({ table, column, replace, namespace }: {
|
|
106
172
|
table: string;
|
|
107
173
|
column: string;
|
|
108
174
|
replace?: boolean;
|
|
175
|
+
namespace?: string[];
|
|
109
176
|
}): Promise<void>;
|
|
110
|
-
createScalarIndex({ table, column, replace }: {
|
|
177
|
+
createScalarIndex({ table, column, replace, namespace }: {
|
|
111
178
|
table: string;
|
|
112
179
|
column: string;
|
|
113
180
|
replace?: boolean;
|
|
181
|
+
namespace?: string[];
|
|
114
182
|
}): Promise<void>;
|
|
115
|
-
createFullTextSearchIndex({ table, column, replace }: {
|
|
183
|
+
createFullTextSearchIndex({ table, column, replace, namespace }: {
|
|
116
184
|
table: string;
|
|
117
185
|
column: string;
|
|
118
186
|
replace?: boolean;
|
|
187
|
+
namespace?: string[];
|
|
119
188
|
}): Promise<void>;
|
|
120
|
-
listIndexes({ table }: {
|
|
189
|
+
listIndexes({ table, namespace }: {
|
|
121
190
|
table: string;
|
|
122
|
-
|
|
191
|
+
namespace?: string[];
|
|
192
|
+
}): Promise<TableIndex[]>;
|
|
123
193
|
}
|
|
194
|
+
export {};
|
|
@@ -302,6 +302,48 @@ function buildWhereClause(where) {
|
|
|
302
302
|
}
|
|
303
303
|
return null;
|
|
304
304
|
}
|
|
305
|
+
function normalizeTableRefs(tables) {
|
|
306
|
+
return tables.map((table) => typeof table === "string" ? { name: table } : table);
|
|
307
|
+
}
|
|
308
|
+
function tableIndexFromJson(value) {
|
|
309
|
+
if (!isRecord(value) || typeof value.name !== "string" || typeof value.type !== "string" || !Array.isArray(value.columns)) {
|
|
310
|
+
throw new room_server_client_1.RoomServerException("unexpected return type from database.list_indexes");
|
|
311
|
+
}
|
|
312
|
+
return {
|
|
313
|
+
name: value.name,
|
|
314
|
+
type: value.type,
|
|
315
|
+
columns: value.columns.map((column) => {
|
|
316
|
+
if (typeof column !== "string") {
|
|
317
|
+
throw new room_server_client_1.RoomServerException("unexpected return type from database.list_indexes");
|
|
318
|
+
}
|
|
319
|
+
return column;
|
|
320
|
+
}),
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
function tableVersionFromJson(value) {
|
|
324
|
+
if (!isRecord(value) || typeof value.metadata_json !== "string" || typeof value.timestamp !== "string" || typeof value.version !== "number") {
|
|
325
|
+
throw new room_server_client_1.RoomServerException("unexpected return type from database.list_versions");
|
|
326
|
+
}
|
|
327
|
+
const timestamp = new Date(value.timestamp);
|
|
328
|
+
if (Number.isNaN(timestamp.getTime())) {
|
|
329
|
+
throw new room_server_client_1.RoomServerException("unexpected return type from database.list_versions");
|
|
330
|
+
}
|
|
331
|
+
let metadata;
|
|
332
|
+
try {
|
|
333
|
+
metadata = JSON.parse(value.metadata_json);
|
|
334
|
+
}
|
|
335
|
+
catch (_) {
|
|
336
|
+
throw new room_server_client_1.RoomServerException("unexpected return type from database.list_versions");
|
|
337
|
+
}
|
|
338
|
+
if (!isRecord(metadata)) {
|
|
339
|
+
throw new room_server_client_1.RoomServerException("unexpected return type from database.list_versions");
|
|
340
|
+
}
|
|
341
|
+
return {
|
|
342
|
+
version: value.version,
|
|
343
|
+
timestamp,
|
|
344
|
+
metadata,
|
|
345
|
+
};
|
|
346
|
+
}
|
|
305
347
|
class DatabaseWriteInputStream {
|
|
306
348
|
constructor(start, chunks) {
|
|
307
349
|
this.start = start;
|
|
@@ -482,79 +524,92 @@ class DatabaseClient {
|
|
|
482
524
|
input.close();
|
|
483
525
|
}
|
|
484
526
|
}
|
|
485
|
-
async listTables() {
|
|
486
|
-
const response = await this.invoke("list_tables", { namespace: null });
|
|
527
|
+
async listTables({ namespace } = {}) {
|
|
528
|
+
const response = await this.invoke("list_tables", { namespace: namespace ?? null });
|
|
487
529
|
if (!(response instanceof response_1.JsonContent)) {
|
|
488
530
|
throw this._unexpectedResponseError("list_tables");
|
|
489
531
|
}
|
|
490
532
|
return Array.isArray(response.json.tables) ? response.json.tables : [];
|
|
491
533
|
}
|
|
492
|
-
async createTable({ name, data, schema, mode = "create", }) {
|
|
534
|
+
async createTable({ name, data, schema, mode = "create", namespace, metadata, }) {
|
|
493
535
|
const input = new DatabaseWriteInputStream({
|
|
494
536
|
kind: "start",
|
|
495
537
|
name,
|
|
496
538
|
fields: schemaEntries(schema),
|
|
497
539
|
mode,
|
|
498
|
-
namespace: null,
|
|
499
|
-
metadata:
|
|
540
|
+
namespace: namespace ?? null,
|
|
541
|
+
metadata: metadataEntries(metadata),
|
|
500
542
|
}, data ?? []);
|
|
501
543
|
await this.drainWriteStream("create_table", input);
|
|
502
544
|
}
|
|
503
|
-
async createTableWithSchema({ name, schema, data, mode = "create" }) {
|
|
545
|
+
async createTableWithSchema({ name, schema, data, mode = "create", namespace, metadata }) {
|
|
504
546
|
return this.createTable({
|
|
505
547
|
name,
|
|
506
548
|
schema,
|
|
507
549
|
data: data == null ? undefined : rowChunkList(data),
|
|
508
550
|
mode,
|
|
551
|
+
namespace,
|
|
552
|
+
metadata,
|
|
509
553
|
});
|
|
510
554
|
}
|
|
511
|
-
async createTableFromData({ name, data, mode = "create" }) {
|
|
555
|
+
async createTableFromData({ name, data, mode = "create", namespace, metadata }) {
|
|
512
556
|
return this.createTable({
|
|
513
557
|
name,
|
|
514
558
|
data: data == null ? undefined : rowChunkList(data),
|
|
515
559
|
mode,
|
|
560
|
+
namespace,
|
|
561
|
+
metadata,
|
|
516
562
|
});
|
|
517
563
|
}
|
|
518
|
-
async createTableFromDataStream({ name, chunks, schema, mode = "create" }) {
|
|
519
|
-
return this.createTable({ name, data: chunks, schema, mode });
|
|
564
|
+
async createTableFromDataStream({ name, chunks, schema, mode = "create", namespace, metadata }) {
|
|
565
|
+
return this.createTable({ name, data: chunks, schema, mode, namespace, metadata });
|
|
520
566
|
}
|
|
521
|
-
async dropTable({ name, ignoreMissing = false }) {
|
|
567
|
+
async dropTable({ name, ignoreMissing = false, namespace }) {
|
|
522
568
|
await this.room.invoke({
|
|
523
569
|
toolkit: "database",
|
|
524
570
|
tool: "drop_table",
|
|
525
|
-
input: { name, ignore_missing: ignoreMissing, namespace: null },
|
|
571
|
+
input: { name, ignore_missing: ignoreMissing, namespace: namespace ?? null },
|
|
526
572
|
});
|
|
527
573
|
}
|
|
528
|
-
async
|
|
574
|
+
async dropIndex({ table, name, namespace }) {
|
|
575
|
+
await this.room.invoke({
|
|
576
|
+
toolkit: "database",
|
|
577
|
+
tool: "drop_index",
|
|
578
|
+
input: { table, name, namespace: namespace ?? null },
|
|
579
|
+
});
|
|
580
|
+
}
|
|
581
|
+
async addColumns({ table, newColumns, namespace }) {
|
|
529
582
|
await this.room.invoke({
|
|
530
583
|
toolkit: "database",
|
|
531
584
|
tool: "add_columns",
|
|
532
585
|
input: {
|
|
533
586
|
table,
|
|
534
|
-
columns: Object.entries(newColumns).map(([name,
|
|
535
|
-
|
|
587
|
+
columns: Object.entries(newColumns).map(([name, value]) => (value instanceof data_types_1.DataType
|
|
588
|
+
? { name, value_sql: null, data_type: toolkitDataTypeJson(value) }
|
|
589
|
+
: { name, value_sql: value, data_type: null })),
|
|
590
|
+
namespace: namespace ?? null,
|
|
536
591
|
},
|
|
537
592
|
});
|
|
538
593
|
}
|
|
539
|
-
async dropColumns({ table, columns }) {
|
|
594
|
+
async dropColumns({ table, columns, namespace }) {
|
|
540
595
|
await this.room.invoke({
|
|
541
596
|
toolkit: "database",
|
|
542
597
|
tool: "drop_columns",
|
|
543
|
-
input: { table, columns, namespace: null },
|
|
598
|
+
input: { table, columns, namespace: namespace ?? null },
|
|
544
599
|
});
|
|
545
600
|
}
|
|
546
|
-
async insert({ table, records }) {
|
|
547
|
-
await this.insertStream({ table, chunks: rowChunkList(records) });
|
|
601
|
+
async insert({ table, records, namespace }) {
|
|
602
|
+
await this.insertStream({ table, chunks: rowChunkList(records), namespace });
|
|
548
603
|
}
|
|
549
|
-
async insertStream({ table, chunks }) {
|
|
604
|
+
async insertStream({ table, chunks, namespace }) {
|
|
550
605
|
const input = new DatabaseWriteInputStream({
|
|
551
606
|
kind: "start",
|
|
552
607
|
table,
|
|
553
|
-
namespace: null,
|
|
608
|
+
namespace: namespace ?? null,
|
|
554
609
|
}, chunks);
|
|
555
610
|
await this.drainWriteStream("insert", input);
|
|
556
611
|
}
|
|
557
|
-
async update({ table, where, values, valuesSql }) {
|
|
612
|
+
async update({ table, where, values, valuesSql, namespace }) {
|
|
558
613
|
await this.room.invoke({
|
|
559
614
|
toolkit: "database",
|
|
560
615
|
tool: "update",
|
|
@@ -563,26 +618,26 @@ class DatabaseClient {
|
|
|
563
618
|
where,
|
|
564
619
|
values: values == null ? null : Object.entries(values).map(([column, value]) => ({ column, value_json: JSON.stringify(encodeLegacyValue(value)) })),
|
|
565
620
|
values_sql: valuesSql == null ? null : Object.entries(valuesSql).map(([column, expression]) => ({ column, expression })),
|
|
566
|
-
namespace: null,
|
|
621
|
+
namespace: namespace ?? null,
|
|
567
622
|
},
|
|
568
623
|
});
|
|
569
624
|
}
|
|
570
|
-
async delete({ table, where }) {
|
|
625
|
+
async delete({ table, where, namespace }) {
|
|
571
626
|
await this.room.invoke({
|
|
572
627
|
toolkit: "database",
|
|
573
628
|
tool: "delete",
|
|
574
|
-
input: { table, where, namespace: null },
|
|
629
|
+
input: { table, where, namespace: namespace ?? null },
|
|
575
630
|
});
|
|
576
631
|
}
|
|
577
|
-
async merge({ table, on, records }) {
|
|
578
|
-
await this.mergeStream({ table, on, chunks: rowChunkList(records) });
|
|
632
|
+
async merge({ table, on, records, namespace }) {
|
|
633
|
+
await this.mergeStream({ table, on, chunks: rowChunkList(records), namespace });
|
|
579
634
|
}
|
|
580
|
-
async mergeStream({ table, on, chunks }) {
|
|
635
|
+
async mergeStream({ table, on, chunks, namespace }) {
|
|
581
636
|
const input = new DatabaseWriteInputStream({
|
|
582
637
|
kind: "start",
|
|
583
638
|
table,
|
|
584
639
|
on,
|
|
585
|
-
namespace: null,
|
|
640
|
+
namespace: namespace ?? null,
|
|
586
641
|
}, chunks);
|
|
587
642
|
await this.drainWriteStream("merge", input);
|
|
588
643
|
}
|
|
@@ -597,18 +652,18 @@ class DatabaseClient {
|
|
|
597
652
|
yield* this.streamRows("sql", {
|
|
598
653
|
kind: "start",
|
|
599
654
|
query,
|
|
600
|
-
tables,
|
|
655
|
+
tables: normalizeTableRefs(tables),
|
|
601
656
|
params_json: params == null ? null : JSON.stringify(encodeLegacyValue(params)),
|
|
602
657
|
});
|
|
603
658
|
}
|
|
604
|
-
async search({ table, text, vector, where, limit, select }) {
|
|
659
|
+
async search({ table, text, vector, where, offset, limit, select, namespace }) {
|
|
605
660
|
const rows = [];
|
|
606
|
-
for await (const chunk of this.searchStream({ table, text, vector, where, limit, select })) {
|
|
661
|
+
for await (const chunk of this.searchStream({ table, text, vector, where, offset, limit, select, namespace })) {
|
|
607
662
|
rows.push(...chunk);
|
|
608
663
|
}
|
|
609
664
|
return rows;
|
|
610
665
|
}
|
|
611
|
-
async *searchStream({ table, text, vector, where, limit, select }) {
|
|
666
|
+
async *searchStream({ table, text, vector, where, offset, limit, select, namespace }) {
|
|
612
667
|
yield* this.streamRows("search", {
|
|
613
668
|
kind: "start",
|
|
614
669
|
table,
|
|
@@ -616,45 +671,91 @@ class DatabaseClient {
|
|
|
616
671
|
vector: vector ?? null,
|
|
617
672
|
text_columns: null,
|
|
618
673
|
where: buildWhereClause(where),
|
|
619
|
-
offset: null,
|
|
674
|
+
offset: offset ?? null,
|
|
620
675
|
limit: limit ?? null,
|
|
621
676
|
select: select ?? null,
|
|
622
|
-
namespace: null,
|
|
677
|
+
namespace: namespace ?? null,
|
|
678
|
+
});
|
|
679
|
+
}
|
|
680
|
+
async count({ table, text, vector, where, namespace }) {
|
|
681
|
+
const response = await this.invoke("count", {
|
|
682
|
+
table,
|
|
683
|
+
text: text ?? null,
|
|
684
|
+
vector: vector ?? null,
|
|
685
|
+
text_columns: null,
|
|
686
|
+
where: buildWhereClause(where),
|
|
687
|
+
namespace: namespace ?? null,
|
|
623
688
|
});
|
|
689
|
+
if (!(response instanceof response_1.JsonContent) || typeof response.json.count !== "number" || !Number.isInteger(response.json.count)) {
|
|
690
|
+
throw this._unexpectedResponseError("count");
|
|
691
|
+
}
|
|
692
|
+
return response.json.count;
|
|
693
|
+
}
|
|
694
|
+
async inspect({ table, namespace }) {
|
|
695
|
+
const response = await this.invoke("inspect", { table, namespace: namespace ?? null });
|
|
696
|
+
if (!(response instanceof response_1.JsonContent) || !Array.isArray(response.json.fields)) {
|
|
697
|
+
throw this._unexpectedResponseError("inspect");
|
|
698
|
+
}
|
|
699
|
+
return Object.fromEntries(response.json.fields.map((field) => {
|
|
700
|
+
if (!isRecord(field) || typeof field.name !== "string") {
|
|
701
|
+
throw this._unexpectedResponseError("inspect");
|
|
702
|
+
}
|
|
703
|
+
return [field.name, data_types_1.DataType.fromJson(publicDataTypeJson(field.data_type))];
|
|
704
|
+
}));
|
|
624
705
|
}
|
|
625
|
-
async optimize(
|
|
626
|
-
|
|
706
|
+
async optimize(tableOrParams) {
|
|
707
|
+
const table = typeof tableOrParams === "string" ? tableOrParams : tableOrParams.table;
|
|
708
|
+
const namespace = typeof tableOrParams === "string" ? undefined : tableOrParams.namespace;
|
|
709
|
+
await this.room.invoke({ toolkit: "database", tool: "optimize", input: { table, namespace: namespace ?? null } });
|
|
627
710
|
}
|
|
628
|
-
async
|
|
711
|
+
async restore({ table, version, namespace }) {
|
|
712
|
+
await this.room.invoke({
|
|
713
|
+
toolkit: "database",
|
|
714
|
+
tool: "restore",
|
|
715
|
+
input: { table, version, namespace: namespace ?? null },
|
|
716
|
+
});
|
|
717
|
+
}
|
|
718
|
+
async checkout({ table, version, namespace }) {
|
|
719
|
+
await this.room.invoke({
|
|
720
|
+
toolkit: "database",
|
|
721
|
+
tool: "checkout",
|
|
722
|
+
input: { table, version, namespace: namespace ?? null },
|
|
723
|
+
});
|
|
724
|
+
}
|
|
725
|
+
async listVersions({ table, namespace }) {
|
|
726
|
+
const response = await this.invoke("list_versions", { table, namespace: namespace ?? null });
|
|
727
|
+
if (!(response instanceof response_1.JsonContent) || !Array.isArray(response.json.versions)) {
|
|
728
|
+
throw this._unexpectedResponseError("list_versions");
|
|
729
|
+
}
|
|
730
|
+
return response.json.versions.map((version) => tableVersionFromJson(version));
|
|
731
|
+
}
|
|
732
|
+
async createVectorIndex({ table, column, replace = false, namespace }) {
|
|
629
733
|
await this.room.invoke({
|
|
630
734
|
toolkit: "database",
|
|
631
735
|
tool: "create_vector_index",
|
|
632
|
-
input: { table, column, replace, namespace: null },
|
|
736
|
+
input: { table, column, replace, namespace: namespace ?? null },
|
|
633
737
|
});
|
|
634
738
|
}
|
|
635
|
-
async createScalarIndex({ table, column, replace = false }) {
|
|
739
|
+
async createScalarIndex({ table, column, replace = false, namespace }) {
|
|
636
740
|
await this.room.invoke({
|
|
637
741
|
toolkit: "database",
|
|
638
742
|
tool: "create_scalar_index",
|
|
639
|
-
input: { table, column, replace, namespace: null },
|
|
743
|
+
input: { table, column, replace, namespace: namespace ?? null },
|
|
640
744
|
});
|
|
641
745
|
}
|
|
642
|
-
async createFullTextSearchIndex({ table, column, replace = false }) {
|
|
746
|
+
async createFullTextSearchIndex({ table, column, replace = false, namespace }) {
|
|
643
747
|
await this.room.invoke({
|
|
644
748
|
toolkit: "database",
|
|
645
749
|
tool: "create_full_text_search_index",
|
|
646
|
-
input: { table, column, replace, namespace: null },
|
|
750
|
+
input: { table, column, replace, namespace: namespace ?? null },
|
|
647
751
|
});
|
|
648
752
|
}
|
|
649
|
-
async listIndexes({ table }) {
|
|
650
|
-
const response = await this.invoke("list_indexes", { table, namespace: null });
|
|
651
|
-
if (!(response instanceof response_1.JsonContent)) {
|
|
652
|
-
throw this._unexpectedResponseError("list_indexes");
|
|
653
|
-
}
|
|
654
|
-
if (!Array.isArray(response.json.indexes)) {
|
|
753
|
+
async listIndexes({ table, namespace }) {
|
|
754
|
+
const response = await this.invoke("list_indexes", { table, namespace: namespace ?? null });
|
|
755
|
+
if (!(response instanceof response_1.JsonContent) || !Array.isArray(response.json.indexes)) {
|
|
655
756
|
throw this._unexpectedResponseError("list_indexes");
|
|
656
757
|
}
|
|
657
|
-
return response.json.indexes;
|
|
758
|
+
return response.json.indexes.map((index) => tableIndexFromJson(index));
|
|
658
759
|
}
|
|
659
760
|
}
|
|
660
761
|
exports.DatabaseClient = DatabaseClient;
|
|
@@ -2,80 +2,61 @@ import { EventEmitter } from "./event-emitter";
|
|
|
2
2
|
import { RoomClient } from "./room-client";
|
|
3
3
|
import { Participant, RemoteParticipant } from "./participant";
|
|
4
4
|
import { RoomMessageEvent } from "./room-event";
|
|
5
|
-
|
|
6
|
-
export declare class MessageStreamChunk {
|
|
7
|
-
header: Record<string, any>;
|
|
8
|
-
data?: Uint8Array;
|
|
9
|
-
constructor({ header, data }: {
|
|
10
|
-
header: Record<string, any>;
|
|
11
|
-
data?: Uint8Array;
|
|
12
|
-
});
|
|
13
|
-
}
|
|
5
|
+
type MessagePayload = Record<string, unknown>;
|
|
14
6
|
export declare class MessagingClient extends EventEmitter<RoomMessageEvent> {
|
|
15
|
-
private client;
|
|
16
|
-
private
|
|
17
|
-
private
|
|
18
|
-
private
|
|
19
|
-
private
|
|
7
|
+
private readonly client;
|
|
8
|
+
private readonly _messageHandler;
|
|
9
|
+
private readonly _participants;
|
|
10
|
+
private readonly _messageQueue;
|
|
11
|
+
private _messageQueued;
|
|
12
|
+
private _sendTask;
|
|
13
|
+
private _messageQueueClosed;
|
|
14
|
+
private _enabled;
|
|
20
15
|
constructor({ room }: {
|
|
21
16
|
room: RoomClient;
|
|
22
17
|
});
|
|
23
18
|
private _messageInput;
|
|
19
|
+
private _syntheticMessageEvent;
|
|
24
20
|
private _removeParticipant;
|
|
21
|
+
private _markParticipantOffline;
|
|
25
22
|
private _resolveMessageRecipient;
|
|
26
|
-
private
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
23
|
+
private _queueMessage;
|
|
24
|
+
private _rejectQueuedMessages;
|
|
25
|
+
private _isParticipantNotFound;
|
|
26
|
+
private _nextQueuedMessage;
|
|
27
|
+
private _sendMessages;
|
|
28
|
+
start(): Promise<void>;
|
|
29
|
+
stop(): Promise<void>;
|
|
31
30
|
sendMessage({ to, type, message, attachment, ignoreOffline }: {
|
|
32
31
|
to: Participant;
|
|
33
32
|
type: string;
|
|
34
|
-
message:
|
|
33
|
+
message: MessagePayload;
|
|
35
34
|
attachment?: Uint8Array;
|
|
36
35
|
ignoreOffline?: boolean;
|
|
37
36
|
}): Promise<void>;
|
|
38
|
-
|
|
37
|
+
sendMessageNowait({ to, type, message, attachment }: {
|
|
38
|
+
to: Participant;
|
|
39
|
+
type: string;
|
|
40
|
+
message: MessagePayload;
|
|
41
|
+
attachment?: Uint8Array;
|
|
42
|
+
}): void;
|
|
43
|
+
enable(): Promise<void>;
|
|
39
44
|
disable(): Promise<void>;
|
|
40
45
|
broadcastMessage({ type, message, attachment }: {
|
|
41
46
|
type: string;
|
|
42
|
-
message:
|
|
47
|
+
message: MessagePayload;
|
|
43
48
|
attachment?: Uint8Array;
|
|
44
49
|
}): Promise<void>;
|
|
45
|
-
get remoteParticipants():
|
|
50
|
+
get remoteParticipants(): RemoteParticipant[];
|
|
51
|
+
get isEnabled(): boolean;
|
|
52
|
+
getParticipants(): RemoteParticipant[];
|
|
53
|
+
getParticipant(id: string): RemoteParticipant | null;
|
|
54
|
+
getParticipantByName(name: string): RemoteParticipant | null;
|
|
46
55
|
private _handleMessageSend;
|
|
47
56
|
private _onParticipantEnabled;
|
|
48
57
|
private _onParticipantAttributes;
|
|
49
58
|
private _onParticipantDisabled;
|
|
50
59
|
private _onMessagingEnabled;
|
|
51
|
-
private _onStreamOpen;
|
|
52
|
-
private _onStreamAccept;
|
|
53
|
-
private _onStreamReject;
|
|
54
|
-
private _onStreamChunk;
|
|
55
|
-
private _onStreamClose;
|
|
56
60
|
dispose(): void;
|
|
57
61
|
}
|
|
58
|
-
export
|
|
59
|
-
private _streamId;
|
|
60
|
-
private _to;
|
|
61
|
-
private _client;
|
|
62
|
-
constructor({ streamId, to, client }: {
|
|
63
|
-
streamId: string;
|
|
64
|
-
to: Participant;
|
|
65
|
-
client: MessagingClient;
|
|
66
|
-
});
|
|
67
|
-
write(chunk: MessageStreamChunk): Promise<void>;
|
|
68
|
-
close(): Promise<void>;
|
|
69
|
-
}
|
|
70
|
-
export declare class MessageStreamReader {
|
|
71
|
-
_streamId: string;
|
|
72
|
-
_to: Participant;
|
|
73
|
-
_client: MessagingClient;
|
|
74
|
-
_controller: StreamController<MessageStreamChunk>;
|
|
75
|
-
constructor({ streamId, to, client, controller }: {
|
|
76
|
-
streamId: string;
|
|
77
|
-
to: Participant;
|
|
78
|
-
client: MessagingClient;
|
|
79
|
-
controller: StreamController<MessageStreamChunk>;
|
|
80
|
-
});
|
|
81
|
-
}
|
|
62
|
+
export {};
|