@meshagent/meshagent 0.3.1 → 0.4.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.
Files changed (84) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/browser/entrypoint.js +7956 -5611
  3. package/dist/browser/helpers.d.ts +10 -4
  4. package/dist/browser/helpers.js +14 -39
  5. package/dist/browser/index.d.ts +1 -0
  6. package/dist/browser/index.js +1 -0
  7. package/dist/browser/participant-token.d.ts +4 -4
  8. package/dist/browser/participant-token.js +4 -9
  9. package/dist/browser/protocol.d.ts +5 -1
  10. package/dist/browser/protocol.js +7 -2
  11. package/dist/browser/room-client.d.ts +4 -1
  12. package/dist/browser/room-client.js +2 -2
  13. package/dist/browser/sync-client.d.ts +5 -1
  14. package/dist/browser/sync-client.js +13 -2
  15. package/dist/esm/agent-client.d.ts +88 -0
  16. package/dist/esm/agent-client.js +166 -0
  17. package/dist/esm/agent.d.ts +103 -0
  18. package/dist/esm/agent.js +218 -0
  19. package/dist/esm/client.d.ts +90 -0
  20. package/dist/esm/client.js +443 -0
  21. package/dist/esm/completer.d.ts +9 -0
  22. package/dist/esm/completer.js +21 -0
  23. package/dist/esm/data-types.d.ts +44 -0
  24. package/dist/esm/data-types.js +110 -0
  25. package/dist/esm/database-client.d.ts +77 -0
  26. package/dist/esm/database-client.js +109 -0
  27. package/dist/esm/developer-client.d.ts +13 -0
  28. package/dist/esm/developer-client.js +31 -0
  29. package/dist/esm/document.d.ts +84 -0
  30. package/dist/esm/document.js +522 -0
  31. package/dist/esm/entrypoint.d.ts +49722 -0
  32. package/dist/esm/entrypoint.js +6313 -0
  33. package/dist/esm/event-emitter.d.ts +13 -0
  34. package/dist/esm/event-emitter.js +34 -0
  35. package/dist/esm/helpers.d.ts +32 -0
  36. package/dist/esm/helpers.js +46 -0
  37. package/dist/esm/index.d.ts +25 -0
  38. package/dist/esm/index.js +25 -0
  39. package/dist/esm/messaging-client.d.ts +76 -0
  40. package/dist/esm/messaging-client.js +241 -0
  41. package/dist/esm/participant-token.d.ts +36 -0
  42. package/dist/esm/participant-token.js +91 -0
  43. package/dist/esm/participant.d.ts +18 -0
  44. package/dist/esm/participant.js +36 -0
  45. package/dist/esm/protocol.d.ts +91 -0
  46. package/dist/esm/protocol.js +287 -0
  47. package/dist/esm/queues-client.d.ts +26 -0
  48. package/dist/esm/queues-client.js +42 -0
  49. package/dist/esm/requirement.d.ts +25 -0
  50. package/dist/esm/requirement.js +42 -0
  51. package/dist/esm/response.d.ts +60 -0
  52. package/dist/esm/response.js +128 -0
  53. package/dist/esm/room-client.d.ts +46 -0
  54. package/dist/esm/room-client.js +106 -0
  55. package/dist/esm/room-event.d.ts +60 -0
  56. package/dist/esm/room-event.js +72 -0
  57. package/dist/esm/room-server-client.d.ts +19 -0
  58. package/dist/esm/room-server-client.js +45 -0
  59. package/dist/esm/runtime.d.ts +6 -0
  60. package/dist/esm/runtime.js +1 -0
  61. package/dist/esm/schema.d.ts +83 -0
  62. package/dist/esm/schema.js +312 -0
  63. package/dist/esm/storage-client.d.ts +38 -0
  64. package/dist/esm/storage-client.js +79 -0
  65. package/dist/esm/stream-controller.d.ts +8 -0
  66. package/dist/esm/stream-controller.js +51 -0
  67. package/dist/esm/sync-client.d.ts +37 -0
  68. package/dist/esm/sync-client.js +125 -0
  69. package/dist/esm/utils.d.ts +14 -0
  70. package/dist/esm/utils.js +44 -0
  71. package/dist/node/entrypoint.js +9 -4
  72. package/dist/node/helpers.d.ts +10 -4
  73. package/dist/node/helpers.js +14 -39
  74. package/dist/node/index.d.ts +1 -0
  75. package/dist/node/index.js +1 -0
  76. package/dist/node/participant-token.d.ts +4 -4
  77. package/dist/node/participant-token.js +4 -9
  78. package/dist/node/protocol.d.ts +5 -1
  79. package/dist/node/protocol.js +7 -2
  80. package/dist/node/room-client.d.ts +4 -1
  81. package/dist/node/room-client.js +2 -2
  82. package/dist/node/sync-client.d.ts +5 -1
  83. package/dist/node/sync-client.js +13 -2
  84. package/package.json +4 -3
@@ -0,0 +1,109 @@
1
+ import { JsonResponse } from "./response";
2
+ export class DatabaseClient {
3
+ constructor({ room }) {
4
+ this.room = room;
5
+ }
6
+ async listTables() {
7
+ const response = await this.room.sendRequest("database.list_tables", {});
8
+ return response?.json?.tables ?? [];
9
+ }
10
+ async createTable({ name, data, schema, mode = "create" }) {
11
+ let schemaDict;
12
+ if (schema) {
13
+ schemaDict = {};
14
+ for (const [key, value] of Object.entries(schema)) {
15
+ schemaDict[key] = value.toJson();
16
+ }
17
+ }
18
+ const payload = {
19
+ name,
20
+ data,
21
+ schema: schemaDict,
22
+ mode,
23
+ };
24
+ await this.room.sendRequest("database.create_table", payload);
25
+ }
26
+ async createTableWithSchema({ name, schema, data, mode = "create" }) {
27
+ return this.createTable({ name, schema, data, mode });
28
+ }
29
+ async createTableFromData({ name, data, mode = "create" }) {
30
+ return this.createTable({ name, data, mode });
31
+ }
32
+ async dropTable({ name, ignoreMissing = false }) {
33
+ await this.room.sendRequest("database.drop_table", { name, ignoreMissing });
34
+ }
35
+ async addColumns({ table, newColumns }) {
36
+ await this.room.sendRequest("database.add_columns", {
37
+ table,
38
+ new_columns: newColumns
39
+ });
40
+ }
41
+ async dropColumns({ table, columns }) {
42
+ await this.room.sendRequest("database.drop_columns", { table, columns });
43
+ }
44
+ async insert({ table, records }) {
45
+ await this.room.sendRequest("database.insert", { table, records });
46
+ }
47
+ async update({ table, where, values, valuesSql }) {
48
+ const payload = {
49
+ table,
50
+ where,
51
+ values,
52
+ valuesSql,
53
+ };
54
+ await this.room.sendRequest("database.update", payload);
55
+ }
56
+ async delete({ table, where }) {
57
+ await this.room.sendRequest("database.delete", { table, where });
58
+ }
59
+ async merge({ table, on, records }) {
60
+ await this.room.sendRequest("database.merge", { table, on, records });
61
+ }
62
+ async search({ table, text, vector, where, limit, select }) {
63
+ let whereClause = where;
64
+ if (where && typeof where === "object" && !Array.isArray(where)) {
65
+ const parts = [];
66
+ for (const [key, value] of Object.entries(where)) {
67
+ parts.push(`${key} = ${JSON.stringify(value)}`);
68
+ }
69
+ whereClause = parts.join(" AND ");
70
+ }
71
+ const payload = {
72
+ table,
73
+ where: whereClause,
74
+ text,
75
+ };
76
+ if (limit !== undefined) {
77
+ payload.limit = limit;
78
+ }
79
+ if (select !== undefined) {
80
+ payload.select = select;
81
+ }
82
+ if (vector !== undefined) {
83
+ payload.vector = vector;
84
+ }
85
+ const response = await this.room.sendRequest("database.search", payload);
86
+ if (response instanceof JsonResponse) {
87
+ if (response?.json?.results) {
88
+ return response.json.results;
89
+ }
90
+ }
91
+ return [];
92
+ }
93
+ async optimize(table) {
94
+ await this.room.sendRequest("database.optimize", { table });
95
+ }
96
+ async createVectorIndex({ table, column }) {
97
+ await this.room.sendRequest("database.create_vector_index", { table, column });
98
+ }
99
+ async createScalarIndex({ table, column }) {
100
+ await this.room.sendRequest("database.create_scalar_index", { table, column });
101
+ }
102
+ async createFullTextSearchIndex({ table, column }) {
103
+ await this.room.sendRequest("database.create_full_text_search_index", { table, column });
104
+ }
105
+ async listIndexes({ table }) {
106
+ const response = await this.room.sendRequest("database.list_indexes", { table });
107
+ return response?.json ?? {};
108
+ }
109
+ }
@@ -0,0 +1,13 @@
1
+ import { EventEmitter } from "./event-emitter";
2
+ import { RoomClient } from "./room-client";
3
+ import { RoomLogEvent } from "./room-event";
4
+ export declare class DeveloperClient extends EventEmitter<RoomLogEvent> {
5
+ private client;
6
+ constructor({ room }: {
7
+ room: RoomClient;
8
+ });
9
+ private _handleDeveloperLog;
10
+ log(type: string, data: Record<string, any>): Promise<void>;
11
+ enable(): Promise<void>;
12
+ disable(): Promise<void>;
13
+ }
@@ -0,0 +1,31 @@
1
+ import { EventEmitter } from "./event-emitter";
2
+ import { packMessage, unpackMessage } from "./utils";
3
+ import { RoomLogEvent } from "./room-event";
4
+ export class DeveloperClient extends EventEmitter {
5
+ constructor({ room }) {
6
+ super();
7
+ this.client = room;
8
+ this.client.protocol.addHandler("developer.log", this._handleDeveloperLog.bind(this));
9
+ }
10
+ async _handleDeveloperLog(protocol, messageId, type, bytes) {
11
+ const [rawJson, _] = unpackMessage(bytes || new Uint8Array());
12
+ const event = new RoomLogEvent({
13
+ type: rawJson["type"],
14
+ data: rawJson["data"],
15
+ });
16
+ this.client.emit(event);
17
+ this.emit("log", event);
18
+ }
19
+ async log(type, data) {
20
+ const message = packMessage({ type, data }, undefined);
21
+ await this.client.protocol.send("developer.log", message);
22
+ }
23
+ async enable() {
24
+ const message = packMessage({}, undefined);
25
+ await this.client.protocol.send("developer.watch", message);
26
+ }
27
+ async disable() {
28
+ const message = packMessage({}, undefined);
29
+ await this.client.protocol.send("developer.unwatch", message);
30
+ }
31
+ }
@@ -0,0 +1,84 @@
1
+ import { MeshSchema, ElementType } from "./schema";
2
+ import { EventEmitter } from "./event-emitter";
3
+ export interface RuntimeDocumentEvent {
4
+ type: string;
5
+ doc: RuntimeDocument;
6
+ }
7
+ export declare class RuntimeDocument extends EventEmitter<RuntimeDocumentEvent> {
8
+ readonly id: string;
9
+ readonly schema: MeshSchema;
10
+ readonly sendChanges: (changes: Record<string, any>) => void;
11
+ readonly sendChangesToBackend?: (msg: string) => void;
12
+ private _changeSubscribers;
13
+ constructor({ id, schema, sendChanges, sendChangesToBackend }: {
14
+ id: string;
15
+ schema: MeshSchema;
16
+ sendChanges: (changes: Record<string, any>) => void;
17
+ sendChangesToBackend?: (msg: string) => void;
18
+ });
19
+ listen(onData: (data: Record<string, any>) => void): {
20
+ unsubscribe: () => void;
21
+ };
22
+ private _root?;
23
+ get root(): Element;
24
+ private _createNode;
25
+ receiveChanges(message: Record<string, any>): void;
26
+ }
27
+ export interface NodeEvent {
28
+ type: string;
29
+ node: Node;
30
+ }
31
+ export declare class Node extends EventEmitter<NodeEvent> {
32
+ parent: Element | null;
33
+ doc: RuntimeDocument;
34
+ constructor({ parent, doc }: {
35
+ parent: Element | null;
36
+ doc: RuntimeDocument;
37
+ });
38
+ }
39
+ export declare class Element extends Node {
40
+ tagName: string;
41
+ attributes: Record<string, any>;
42
+ elementType: ElementType;
43
+ children: Node[];
44
+ constructor({ parent, tagName, attributes, doc, elementType }: {
45
+ parent: Element | null;
46
+ tagName: string;
47
+ attributes: Record<string, any>;
48
+ doc: RuntimeDocument;
49
+ elementType: ElementType;
50
+ });
51
+ getNodeByID(id: string): Element | null;
52
+ get id(): string | undefined;
53
+ getAttribute(name: string): any;
54
+ setAttribute(name: string, value: any): void;
55
+ removeAttribute(name: string): void;
56
+ private _ensureChildValid;
57
+ private _validateElementAttributes;
58
+ createChildElement(tagName: string, attributes: Record<string, any>, opts?: {
59
+ id?: string;
60
+ }): Element;
61
+ createChildElementAt(index: number, tagName: string, attributes: Record<string, any>, opts?: {
62
+ id?: string;
63
+ }): Element;
64
+ createChildElementAfter(element: Element, tagName: string, attributes: Record<string, any>, opts?: {
65
+ id?: string;
66
+ }): Element;
67
+ private _defaultChildren;
68
+ delete(): void;
69
+ getChildren(): Node[];
70
+ appendJson(json: Record<string, any>): Element;
71
+ }
72
+ export declare class TextElement extends Node {
73
+ delta: Array<Record<string, any>>;
74
+ constructor({ parent, delta, doc }: {
75
+ parent: Element;
76
+ delta: Array<Record<string, any>>;
77
+ doc: RuntimeDocument;
78
+ });
79
+ insert(index: number, text: string, attributes?: Record<string, any>): void;
80
+ format(from: number, length: number, attributes: Record<string, any>): void;
81
+ delete(index: number, length: number): void;
82
+ }
83
+ export declare function tagNameFromJson(json: Record<string, any>): string;
84
+ export declare function attributesFromJson(json: Record<string, any>): Record<string, any>;