@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 {};
|
|
@@ -299,6 +299,48 @@ function buildWhereClause(where) {
|
|
|
299
299
|
}
|
|
300
300
|
return null;
|
|
301
301
|
}
|
|
302
|
+
function normalizeTableRefs(tables) {
|
|
303
|
+
return tables.map((table) => typeof table === "string" ? { name: table } : table);
|
|
304
|
+
}
|
|
305
|
+
function tableIndexFromJson(value) {
|
|
306
|
+
if (!isRecord(value) || typeof value.name !== "string" || typeof value.type !== "string" || !Array.isArray(value.columns)) {
|
|
307
|
+
throw new RoomServerException("unexpected return type from database.list_indexes");
|
|
308
|
+
}
|
|
309
|
+
return {
|
|
310
|
+
name: value.name,
|
|
311
|
+
type: value.type,
|
|
312
|
+
columns: value.columns.map((column) => {
|
|
313
|
+
if (typeof column !== "string") {
|
|
314
|
+
throw new RoomServerException("unexpected return type from database.list_indexes");
|
|
315
|
+
}
|
|
316
|
+
return column;
|
|
317
|
+
}),
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
function tableVersionFromJson(value) {
|
|
321
|
+
if (!isRecord(value) || typeof value.metadata_json !== "string" || typeof value.timestamp !== "string" || typeof value.version !== "number") {
|
|
322
|
+
throw new RoomServerException("unexpected return type from database.list_versions");
|
|
323
|
+
}
|
|
324
|
+
const timestamp = new Date(value.timestamp);
|
|
325
|
+
if (Number.isNaN(timestamp.getTime())) {
|
|
326
|
+
throw new RoomServerException("unexpected return type from database.list_versions");
|
|
327
|
+
}
|
|
328
|
+
let metadata;
|
|
329
|
+
try {
|
|
330
|
+
metadata = JSON.parse(value.metadata_json);
|
|
331
|
+
}
|
|
332
|
+
catch (_) {
|
|
333
|
+
throw new RoomServerException("unexpected return type from database.list_versions");
|
|
334
|
+
}
|
|
335
|
+
if (!isRecord(metadata)) {
|
|
336
|
+
throw new RoomServerException("unexpected return type from database.list_versions");
|
|
337
|
+
}
|
|
338
|
+
return {
|
|
339
|
+
version: value.version,
|
|
340
|
+
timestamp,
|
|
341
|
+
metadata,
|
|
342
|
+
};
|
|
343
|
+
}
|
|
302
344
|
class DatabaseWriteInputStream {
|
|
303
345
|
constructor(start, chunks) {
|
|
304
346
|
this.start = start;
|
|
@@ -479,79 +521,92 @@ export class DatabaseClient {
|
|
|
479
521
|
input.close();
|
|
480
522
|
}
|
|
481
523
|
}
|
|
482
|
-
async listTables() {
|
|
483
|
-
const response = await this.invoke("list_tables", { namespace: null });
|
|
524
|
+
async listTables({ namespace } = {}) {
|
|
525
|
+
const response = await this.invoke("list_tables", { namespace: namespace ?? null });
|
|
484
526
|
if (!(response instanceof JsonContent)) {
|
|
485
527
|
throw this._unexpectedResponseError("list_tables");
|
|
486
528
|
}
|
|
487
529
|
return Array.isArray(response.json.tables) ? response.json.tables : [];
|
|
488
530
|
}
|
|
489
|
-
async createTable({ name, data, schema, mode = "create", }) {
|
|
531
|
+
async createTable({ name, data, schema, mode = "create", namespace, metadata, }) {
|
|
490
532
|
const input = new DatabaseWriteInputStream({
|
|
491
533
|
kind: "start",
|
|
492
534
|
name,
|
|
493
535
|
fields: schemaEntries(schema),
|
|
494
536
|
mode,
|
|
495
|
-
namespace: null,
|
|
496
|
-
metadata:
|
|
537
|
+
namespace: namespace ?? null,
|
|
538
|
+
metadata: metadataEntries(metadata),
|
|
497
539
|
}, data ?? []);
|
|
498
540
|
await this.drainWriteStream("create_table", input);
|
|
499
541
|
}
|
|
500
|
-
async createTableWithSchema({ name, schema, data, mode = "create" }) {
|
|
542
|
+
async createTableWithSchema({ name, schema, data, mode = "create", namespace, metadata }) {
|
|
501
543
|
return this.createTable({
|
|
502
544
|
name,
|
|
503
545
|
schema,
|
|
504
546
|
data: data == null ? undefined : rowChunkList(data),
|
|
505
547
|
mode,
|
|
548
|
+
namespace,
|
|
549
|
+
metadata,
|
|
506
550
|
});
|
|
507
551
|
}
|
|
508
|
-
async createTableFromData({ name, data, mode = "create" }) {
|
|
552
|
+
async createTableFromData({ name, data, mode = "create", namespace, metadata }) {
|
|
509
553
|
return this.createTable({
|
|
510
554
|
name,
|
|
511
555
|
data: data == null ? undefined : rowChunkList(data),
|
|
512
556
|
mode,
|
|
557
|
+
namespace,
|
|
558
|
+
metadata,
|
|
513
559
|
});
|
|
514
560
|
}
|
|
515
|
-
async createTableFromDataStream({ name, chunks, schema, mode = "create" }) {
|
|
516
|
-
return this.createTable({ name, data: chunks, schema, mode });
|
|
561
|
+
async createTableFromDataStream({ name, chunks, schema, mode = "create", namespace, metadata }) {
|
|
562
|
+
return this.createTable({ name, data: chunks, schema, mode, namespace, metadata });
|
|
517
563
|
}
|
|
518
|
-
async dropTable({ name, ignoreMissing = false }) {
|
|
564
|
+
async dropTable({ name, ignoreMissing = false, namespace }) {
|
|
519
565
|
await this.room.invoke({
|
|
520
566
|
toolkit: "database",
|
|
521
567
|
tool: "drop_table",
|
|
522
|
-
input: { name, ignore_missing: ignoreMissing, namespace: null },
|
|
568
|
+
input: { name, ignore_missing: ignoreMissing, namespace: namespace ?? null },
|
|
523
569
|
});
|
|
524
570
|
}
|
|
525
|
-
async
|
|
571
|
+
async dropIndex({ table, name, namespace }) {
|
|
572
|
+
await this.room.invoke({
|
|
573
|
+
toolkit: "database",
|
|
574
|
+
tool: "drop_index",
|
|
575
|
+
input: { table, name, namespace: namespace ?? null },
|
|
576
|
+
});
|
|
577
|
+
}
|
|
578
|
+
async addColumns({ table, newColumns, namespace }) {
|
|
526
579
|
await this.room.invoke({
|
|
527
580
|
toolkit: "database",
|
|
528
581
|
tool: "add_columns",
|
|
529
582
|
input: {
|
|
530
583
|
table,
|
|
531
|
-
columns: Object.entries(newColumns).map(([name,
|
|
532
|
-
|
|
584
|
+
columns: Object.entries(newColumns).map(([name, value]) => (value instanceof DataType
|
|
585
|
+
? { name, value_sql: null, data_type: toolkitDataTypeJson(value) }
|
|
586
|
+
: { name, value_sql: value, data_type: null })),
|
|
587
|
+
namespace: namespace ?? null,
|
|
533
588
|
},
|
|
534
589
|
});
|
|
535
590
|
}
|
|
536
|
-
async dropColumns({ table, columns }) {
|
|
591
|
+
async dropColumns({ table, columns, namespace }) {
|
|
537
592
|
await this.room.invoke({
|
|
538
593
|
toolkit: "database",
|
|
539
594
|
tool: "drop_columns",
|
|
540
|
-
input: { table, columns, namespace: null },
|
|
595
|
+
input: { table, columns, namespace: namespace ?? null },
|
|
541
596
|
});
|
|
542
597
|
}
|
|
543
|
-
async insert({ table, records }) {
|
|
544
|
-
await this.insertStream({ table, chunks: rowChunkList(records) });
|
|
598
|
+
async insert({ table, records, namespace }) {
|
|
599
|
+
await this.insertStream({ table, chunks: rowChunkList(records), namespace });
|
|
545
600
|
}
|
|
546
|
-
async insertStream({ table, chunks }) {
|
|
601
|
+
async insertStream({ table, chunks, namespace }) {
|
|
547
602
|
const input = new DatabaseWriteInputStream({
|
|
548
603
|
kind: "start",
|
|
549
604
|
table,
|
|
550
|
-
namespace: null,
|
|
605
|
+
namespace: namespace ?? null,
|
|
551
606
|
}, chunks);
|
|
552
607
|
await this.drainWriteStream("insert", input);
|
|
553
608
|
}
|
|
554
|
-
async update({ table, where, values, valuesSql }) {
|
|
609
|
+
async update({ table, where, values, valuesSql, namespace }) {
|
|
555
610
|
await this.room.invoke({
|
|
556
611
|
toolkit: "database",
|
|
557
612
|
tool: "update",
|
|
@@ -560,26 +615,26 @@ export class DatabaseClient {
|
|
|
560
615
|
where,
|
|
561
616
|
values: values == null ? null : Object.entries(values).map(([column, value]) => ({ column, value_json: JSON.stringify(encodeLegacyValue(value)) })),
|
|
562
617
|
values_sql: valuesSql == null ? null : Object.entries(valuesSql).map(([column, expression]) => ({ column, expression })),
|
|
563
|
-
namespace: null,
|
|
618
|
+
namespace: namespace ?? null,
|
|
564
619
|
},
|
|
565
620
|
});
|
|
566
621
|
}
|
|
567
|
-
async delete({ table, where }) {
|
|
622
|
+
async delete({ table, where, namespace }) {
|
|
568
623
|
await this.room.invoke({
|
|
569
624
|
toolkit: "database",
|
|
570
625
|
tool: "delete",
|
|
571
|
-
input: { table, where, namespace: null },
|
|
626
|
+
input: { table, where, namespace: namespace ?? null },
|
|
572
627
|
});
|
|
573
628
|
}
|
|
574
|
-
async merge({ table, on, records }) {
|
|
575
|
-
await this.mergeStream({ table, on, chunks: rowChunkList(records) });
|
|
629
|
+
async merge({ table, on, records, namespace }) {
|
|
630
|
+
await this.mergeStream({ table, on, chunks: rowChunkList(records), namespace });
|
|
576
631
|
}
|
|
577
|
-
async mergeStream({ table, on, chunks }) {
|
|
632
|
+
async mergeStream({ table, on, chunks, namespace }) {
|
|
578
633
|
const input = new DatabaseWriteInputStream({
|
|
579
634
|
kind: "start",
|
|
580
635
|
table,
|
|
581
636
|
on,
|
|
582
|
-
namespace: null,
|
|
637
|
+
namespace: namespace ?? null,
|
|
583
638
|
}, chunks);
|
|
584
639
|
await this.drainWriteStream("merge", input);
|
|
585
640
|
}
|
|
@@ -594,18 +649,18 @@ export class DatabaseClient {
|
|
|
594
649
|
yield* this.streamRows("sql", {
|
|
595
650
|
kind: "start",
|
|
596
651
|
query,
|
|
597
|
-
tables,
|
|
652
|
+
tables: normalizeTableRefs(tables),
|
|
598
653
|
params_json: params == null ? null : JSON.stringify(encodeLegacyValue(params)),
|
|
599
654
|
});
|
|
600
655
|
}
|
|
601
|
-
async search({ table, text, vector, where, limit, select }) {
|
|
656
|
+
async search({ table, text, vector, where, offset, limit, select, namespace }) {
|
|
602
657
|
const rows = [];
|
|
603
|
-
for await (const chunk of this.searchStream({ table, text, vector, where, limit, select })) {
|
|
658
|
+
for await (const chunk of this.searchStream({ table, text, vector, where, offset, limit, select, namespace })) {
|
|
604
659
|
rows.push(...chunk);
|
|
605
660
|
}
|
|
606
661
|
return rows;
|
|
607
662
|
}
|
|
608
|
-
async *searchStream({ table, text, vector, where, limit, select }) {
|
|
663
|
+
async *searchStream({ table, text, vector, where, offset, limit, select, namespace }) {
|
|
609
664
|
yield* this.streamRows("search", {
|
|
610
665
|
kind: "start",
|
|
611
666
|
table,
|
|
@@ -613,44 +668,90 @@ export class DatabaseClient {
|
|
|
613
668
|
vector: vector ?? null,
|
|
614
669
|
text_columns: null,
|
|
615
670
|
where: buildWhereClause(where),
|
|
616
|
-
offset: null,
|
|
671
|
+
offset: offset ?? null,
|
|
617
672
|
limit: limit ?? null,
|
|
618
673
|
select: select ?? null,
|
|
619
|
-
namespace: null,
|
|
674
|
+
namespace: namespace ?? null,
|
|
675
|
+
});
|
|
676
|
+
}
|
|
677
|
+
async count({ table, text, vector, where, namespace }) {
|
|
678
|
+
const response = await this.invoke("count", {
|
|
679
|
+
table,
|
|
680
|
+
text: text ?? null,
|
|
681
|
+
vector: vector ?? null,
|
|
682
|
+
text_columns: null,
|
|
683
|
+
where: buildWhereClause(where),
|
|
684
|
+
namespace: namespace ?? null,
|
|
620
685
|
});
|
|
686
|
+
if (!(response instanceof JsonContent) || typeof response.json.count !== "number" || !Number.isInteger(response.json.count)) {
|
|
687
|
+
throw this._unexpectedResponseError("count");
|
|
688
|
+
}
|
|
689
|
+
return response.json.count;
|
|
690
|
+
}
|
|
691
|
+
async inspect({ table, namespace }) {
|
|
692
|
+
const response = await this.invoke("inspect", { table, namespace: namespace ?? null });
|
|
693
|
+
if (!(response instanceof JsonContent) || !Array.isArray(response.json.fields)) {
|
|
694
|
+
throw this._unexpectedResponseError("inspect");
|
|
695
|
+
}
|
|
696
|
+
return Object.fromEntries(response.json.fields.map((field) => {
|
|
697
|
+
if (!isRecord(field) || typeof field.name !== "string") {
|
|
698
|
+
throw this._unexpectedResponseError("inspect");
|
|
699
|
+
}
|
|
700
|
+
return [field.name, DataType.fromJson(publicDataTypeJson(field.data_type))];
|
|
701
|
+
}));
|
|
621
702
|
}
|
|
622
|
-
async optimize(
|
|
623
|
-
|
|
703
|
+
async optimize(tableOrParams) {
|
|
704
|
+
const table = typeof tableOrParams === "string" ? tableOrParams : tableOrParams.table;
|
|
705
|
+
const namespace = typeof tableOrParams === "string" ? undefined : tableOrParams.namespace;
|
|
706
|
+
await this.room.invoke({ toolkit: "database", tool: "optimize", input: { table, namespace: namespace ?? null } });
|
|
624
707
|
}
|
|
625
|
-
async
|
|
708
|
+
async restore({ table, version, namespace }) {
|
|
709
|
+
await this.room.invoke({
|
|
710
|
+
toolkit: "database",
|
|
711
|
+
tool: "restore",
|
|
712
|
+
input: { table, version, namespace: namespace ?? null },
|
|
713
|
+
});
|
|
714
|
+
}
|
|
715
|
+
async checkout({ table, version, namespace }) {
|
|
716
|
+
await this.room.invoke({
|
|
717
|
+
toolkit: "database",
|
|
718
|
+
tool: "checkout",
|
|
719
|
+
input: { table, version, namespace: namespace ?? null },
|
|
720
|
+
});
|
|
721
|
+
}
|
|
722
|
+
async listVersions({ table, namespace }) {
|
|
723
|
+
const response = await this.invoke("list_versions", { table, namespace: namespace ?? null });
|
|
724
|
+
if (!(response instanceof JsonContent) || !Array.isArray(response.json.versions)) {
|
|
725
|
+
throw this._unexpectedResponseError("list_versions");
|
|
726
|
+
}
|
|
727
|
+
return response.json.versions.map((version) => tableVersionFromJson(version));
|
|
728
|
+
}
|
|
729
|
+
async createVectorIndex({ table, column, replace = false, namespace }) {
|
|
626
730
|
await this.room.invoke({
|
|
627
731
|
toolkit: "database",
|
|
628
732
|
tool: "create_vector_index",
|
|
629
|
-
input: { table, column, replace, namespace: null },
|
|
733
|
+
input: { table, column, replace, namespace: namespace ?? null },
|
|
630
734
|
});
|
|
631
735
|
}
|
|
632
|
-
async createScalarIndex({ table, column, replace = false }) {
|
|
736
|
+
async createScalarIndex({ table, column, replace = false, namespace }) {
|
|
633
737
|
await this.room.invoke({
|
|
634
738
|
toolkit: "database",
|
|
635
739
|
tool: "create_scalar_index",
|
|
636
|
-
input: { table, column, replace, namespace: null },
|
|
740
|
+
input: { table, column, replace, namespace: namespace ?? null },
|
|
637
741
|
});
|
|
638
742
|
}
|
|
639
|
-
async createFullTextSearchIndex({ table, column, replace = false }) {
|
|
743
|
+
async createFullTextSearchIndex({ table, column, replace = false, namespace }) {
|
|
640
744
|
await this.room.invoke({
|
|
641
745
|
toolkit: "database",
|
|
642
746
|
tool: "create_full_text_search_index",
|
|
643
|
-
input: { table, column, replace, namespace: null },
|
|
747
|
+
input: { table, column, replace, namespace: namespace ?? null },
|
|
644
748
|
});
|
|
645
749
|
}
|
|
646
|
-
async listIndexes({ table }) {
|
|
647
|
-
const response = await this.invoke("list_indexes", { table, namespace: null });
|
|
648
|
-
if (!(response instanceof JsonContent)) {
|
|
649
|
-
throw this._unexpectedResponseError("list_indexes");
|
|
650
|
-
}
|
|
651
|
-
if (!Array.isArray(response.json.indexes)) {
|
|
750
|
+
async listIndexes({ table, namespace }) {
|
|
751
|
+
const response = await this.invoke("list_indexes", { table, namespace: namespace ?? null });
|
|
752
|
+
if (!(response instanceof JsonContent) || !Array.isArray(response.json.indexes)) {
|
|
652
753
|
throw this._unexpectedResponseError("list_indexes");
|
|
653
754
|
}
|
|
654
|
-
return response.json.indexes;
|
|
755
|
+
return response.json.indexes.map((index) => tableIndexFromJson(index));
|
|
655
756
|
}
|
|
656
757
|
}
|
|
@@ -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 {};
|