@meshagent/meshagent 0.0.11 → 0.0.13
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/dist/browser/agent-client.d.ts +88 -0
- package/dist/browser/agent-client.js +174 -0
- package/dist/browser/agent.d.ts +103 -0
- package/dist/browser/agent.js +229 -0
- package/dist/browser/client.d.ts +90 -0
- package/dist/browser/client.js +449 -0
- package/dist/browser/completer.d.ts +9 -0
- package/dist/browser/completer.js +25 -0
- package/dist/browser/data-types.d.ts +44 -0
- package/dist/browser/data-types.js +119 -0
- package/dist/browser/database-client.d.ts +77 -0
- package/dist/browser/database-client.js +113 -0
- package/dist/browser/developer-client.d.ts +13 -0
- package/dist/browser/developer-client.js +35 -0
- package/dist/browser/document.d.ts +84 -0
- package/dist/browser/document.js +531 -0
- package/dist/browser/entrypoint.d.ts +49722 -0
- package/dist/browser/entrypoint.js +8659 -0
- package/dist/browser/event-emitter.d.ts +13 -0
- package/dist/browser/event-emitter.js +38 -0
- package/dist/browser/helpers.d.ts +26 -0
- package/dist/browser/helpers.js +79 -0
- package/dist/browser/index.d.ts +24 -0
- package/dist/browser/index.js +40 -0
- package/dist/browser/messaging-client.d.ts +76 -0
- package/dist/browser/messaging-client.js +248 -0
- package/dist/browser/participant-token.d.ts +36 -0
- package/dist/browser/participant-token.js +104 -0
- package/dist/browser/participant.d.ts +18 -0
- package/dist/browser/participant.js +42 -0
- package/dist/browser/protocol.d.ts +87 -0
- package/dist/browser/protocol.js +305 -0
- package/dist/browser/queues-client.d.ts +26 -0
- package/dist/browser/queues-client.js +47 -0
- package/dist/browser/requirement.d.ts +25 -0
- package/dist/browser/requirement.js +49 -0
- package/dist/browser/response.d.ts +60 -0
- package/dist/browser/response.js +138 -0
- package/dist/browser/room-client.d.ts +43 -0
- package/dist/browser/room-client.js +109 -0
- package/dist/browser/room-event.d.ts +60 -0
- package/dist/browser/room-event.js +82 -0
- package/dist/browser/room-server-client.d.ts +19 -0
- package/dist/browser/room-server-client.js +50 -0
- package/dist/browser/runtime.d.ts +6 -0
- package/dist/browser/runtime.js +8 -0
- package/dist/browser/schema.d.ts +83 -0
- package/dist/browser/schema.js +321 -0
- package/dist/browser/storage-client.d.ts +38 -0
- package/dist/browser/storage-client.js +86 -0
- package/dist/browser/stream-controller.d.ts +8 -0
- package/dist/browser/stream-controller.js +55 -0
- package/dist/browser/sync-client.d.ts +33 -0
- package/dist/browser/sync-client.js +123 -0
- package/dist/browser/utils.d.ts +14 -0
- package/dist/browser/utils.js +59 -0
- package/dist/node/agent-client.d.ts +88 -0
- package/dist/node/agent-client.js +174 -0
- package/dist/node/agent.d.ts +103 -0
- package/dist/node/agent.js +229 -0
- package/dist/node/client.d.ts +90 -0
- package/dist/node/client.js +449 -0
- package/dist/node/completer.d.ts +9 -0
- package/dist/node/completer.js +25 -0
- package/dist/node/data-types.d.ts +44 -0
- package/dist/node/data-types.js +119 -0
- package/dist/node/database-client.d.ts +77 -0
- package/dist/node/database-client.js +113 -0
- package/dist/node/developer-client.d.ts +13 -0
- package/dist/node/developer-client.js +35 -0
- package/dist/node/document.d.ts +84 -0
- package/dist/node/document.js +531 -0
- package/dist/node/entrypoint.d.ts +49722 -0
- package/dist/node/entrypoint.js +6321 -0
- package/dist/node/event-emitter.d.ts +13 -0
- package/dist/node/event-emitter.js +38 -0
- package/dist/node/helpers.d.ts +26 -0
- package/dist/node/helpers.js +79 -0
- package/dist/node/index.d.ts +24 -0
- package/dist/node/index.js +40 -0
- package/dist/node/messaging-client.d.ts +76 -0
- package/dist/node/messaging-client.js +248 -0
- package/dist/node/participant-token.d.ts +36 -0
- package/dist/node/participant-token.js +104 -0
- package/dist/node/participant.d.ts +18 -0
- package/dist/node/participant.js +42 -0
- package/dist/node/protocol.d.ts +87 -0
- package/dist/node/protocol.js +305 -0
- package/dist/node/queues-client.d.ts +26 -0
- package/dist/node/queues-client.js +47 -0
- package/dist/node/requirement.d.ts +25 -0
- package/dist/node/requirement.js +49 -0
- package/dist/node/response.d.ts +60 -0
- package/dist/node/response.js +138 -0
- package/dist/node/room-client.d.ts +43 -0
- package/dist/node/room-client.js +109 -0
- package/dist/node/room-event.d.ts +60 -0
- package/dist/node/room-event.js +82 -0
- package/dist/node/room-server-client.d.ts +19 -0
- package/dist/node/room-server-client.js +50 -0
- package/dist/node/runtime.d.ts +6 -0
- package/dist/node/runtime.js +8 -0
- package/dist/node/schema.d.ts +83 -0
- package/dist/node/schema.js +321 -0
- package/dist/node/storage-client.d.ts +38 -0
- package/dist/node/storage-client.js +86 -0
- package/dist/node/stream-controller.d.ts +8 -0
- package/dist/node/stream-controller.js +55 -0
- package/dist/node/sync-client.d.ts +33 -0
- package/dist/node/sync-client.js +123 -0
- package/dist/node/utils.d.ts +14 -0
- package/dist/node/utils.js +59 -0
- package/package.json +35 -22
- package/README.md +0 -0
- package/babel.config.cjs +0 -3
- package/client.js +0 -422
- package/dist/entrypoint.js +0 -11262
- package/dist/entrypoint.js.map +0 -7
- package/document-server-client.js +0 -246
- package/entrypoint.js +0 -11568
- package/index.js +0 -2
- package/protocol.js +0 -459
- package/server.js +0 -310
- package/test/assert.js +0 -19
- package/test/document-server-client.test.js +0 -33
- package/test/document.test.js +0 -313
- package/test/protocol.test.js +0 -64
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EmptyResponse = exports.ErrorResponse = exports.JsonResponse = exports.TextResponse = exports.FileResponse = exports.LinkResponse = void 0;
|
|
4
|
+
exports.unpackResponse = unpackResponse;
|
|
5
|
+
const utils_1 = require("./utils");
|
|
6
|
+
class LinkResponse {
|
|
7
|
+
constructor({ url, name }) {
|
|
8
|
+
this.url = url;
|
|
9
|
+
this.name = name;
|
|
10
|
+
}
|
|
11
|
+
static unpack(header, payload) {
|
|
12
|
+
return new LinkResponse({
|
|
13
|
+
url: header["url"],
|
|
14
|
+
name: header["name"],
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
pack() {
|
|
18
|
+
return (0, utils_1.packMessage)({
|
|
19
|
+
type: "link",
|
|
20
|
+
name: this.name,
|
|
21
|
+
url: this.url,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
toString() {
|
|
25
|
+
return `LinkResponse (${this.name}): ${this.url}`;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.LinkResponse = LinkResponse;
|
|
29
|
+
class FileResponse {
|
|
30
|
+
constructor({ data, name, mimeType }) {
|
|
31
|
+
this.data = data;
|
|
32
|
+
this.name = name;
|
|
33
|
+
this.mimeType = mimeType;
|
|
34
|
+
}
|
|
35
|
+
static unpack(header, payload) {
|
|
36
|
+
return new FileResponse({
|
|
37
|
+
data: payload,
|
|
38
|
+
name: header["name"],
|
|
39
|
+
mimeType: header["mime_type"],
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
pack() {
|
|
43
|
+
return (0, utils_1.packMessage)({
|
|
44
|
+
type: "file",
|
|
45
|
+
name: this.name,
|
|
46
|
+
mime_type: this.mimeType,
|
|
47
|
+
}, this.data);
|
|
48
|
+
}
|
|
49
|
+
toString() {
|
|
50
|
+
return `FileResponse (${this.name}): ${this.mimeType}`;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.FileResponse = FileResponse;
|
|
54
|
+
class TextResponse {
|
|
55
|
+
constructor({ text }) {
|
|
56
|
+
this.text = text;
|
|
57
|
+
}
|
|
58
|
+
static unpack(header, payload) {
|
|
59
|
+
return new TextResponse({
|
|
60
|
+
text: header["text"],
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
pack() {
|
|
64
|
+
return (0, utils_1.packMessage)({
|
|
65
|
+
type: "text",
|
|
66
|
+
text: this.text,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
toString() {
|
|
70
|
+
return `TextResponse: ${this.text}`;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
exports.TextResponse = TextResponse;
|
|
74
|
+
class JsonResponse {
|
|
75
|
+
constructor({ json }) {
|
|
76
|
+
this.json = json;
|
|
77
|
+
}
|
|
78
|
+
static unpack(header, payload) {
|
|
79
|
+
return new JsonResponse({ json: header["json"] });
|
|
80
|
+
}
|
|
81
|
+
pack() {
|
|
82
|
+
return (0, utils_1.packMessage)({
|
|
83
|
+
type: "json",
|
|
84
|
+
json: this.json,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
toString() {
|
|
88
|
+
return `JsonResponse: ${JSON.stringify(this.json)}`;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
exports.JsonResponse = JsonResponse;
|
|
92
|
+
class ErrorResponse {
|
|
93
|
+
constructor({ text }) {
|
|
94
|
+
this.text = text;
|
|
95
|
+
}
|
|
96
|
+
static unpack(header, payload) {
|
|
97
|
+
return new ErrorResponse({ text: header["text"] });
|
|
98
|
+
}
|
|
99
|
+
pack() {
|
|
100
|
+
return (0, utils_1.packMessage)({
|
|
101
|
+
type: "error",
|
|
102
|
+
text: this.text,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
toString() {
|
|
106
|
+
return `ErrorResponse: ${this.text}`;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
exports.ErrorResponse = ErrorResponse;
|
|
110
|
+
class EmptyResponse {
|
|
111
|
+
static unpack(header, payload) {
|
|
112
|
+
return new EmptyResponse();
|
|
113
|
+
}
|
|
114
|
+
pack() {
|
|
115
|
+
return (0, utils_1.packMessage)({ type: "empty" });
|
|
116
|
+
}
|
|
117
|
+
toString() {
|
|
118
|
+
return `EmptyResponse`;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
exports.EmptyResponse = EmptyResponse;
|
|
122
|
+
const _responseTypes = {
|
|
123
|
+
empty: EmptyResponse.unpack,
|
|
124
|
+
error: ErrorResponse.unpack,
|
|
125
|
+
file: FileResponse.unpack,
|
|
126
|
+
json: JsonResponse.unpack,
|
|
127
|
+
link: LinkResponse.unpack,
|
|
128
|
+
text: TextResponse.unpack,
|
|
129
|
+
};
|
|
130
|
+
function unpackResponse(data) {
|
|
131
|
+
const header = JSON.parse((0, utils_1.splitMessageHeader)(data));
|
|
132
|
+
const payload = (0, utils_1.splitMessagePayload)(data);
|
|
133
|
+
const typeKey = header["type"];
|
|
134
|
+
if (!_responseTypes[typeKey]) {
|
|
135
|
+
throw new Error(`Unknown response type: ${typeKey}`);
|
|
136
|
+
}
|
|
137
|
+
return _responseTypes[typeKey](header, payload);
|
|
138
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Protocol } from "./protocol";
|
|
2
|
+
import { LocalParticipant } from "./participant";
|
|
3
|
+
import { SyncClient } from "./sync-client";
|
|
4
|
+
import { DeveloperClient } from "./developer-client";
|
|
5
|
+
import { StorageClient } from "./storage-client";
|
|
6
|
+
import { MessagingClient } from "./messaging-client";
|
|
7
|
+
import { QueuesClient } from "./queues-client";
|
|
8
|
+
import { DatabaseClient } from "./database-client";
|
|
9
|
+
import { AgentsClient } from "./agent-client";
|
|
10
|
+
import { RoomEvent } from "./room-event";
|
|
11
|
+
import { Response } from "./response";
|
|
12
|
+
interface RequestHeader {
|
|
13
|
+
[key: string]: any;
|
|
14
|
+
}
|
|
15
|
+
export declare class RoomClient {
|
|
16
|
+
protocol: Protocol;
|
|
17
|
+
readonly sync: SyncClient;
|
|
18
|
+
readonly storage: StorageClient;
|
|
19
|
+
readonly developer: DeveloperClient;
|
|
20
|
+
readonly messaging: MessagingClient;
|
|
21
|
+
readonly queues: QueuesClient;
|
|
22
|
+
readonly database: DatabaseClient;
|
|
23
|
+
readonly agents: AgentsClient;
|
|
24
|
+
private _pendingRequests;
|
|
25
|
+
private _ready;
|
|
26
|
+
private _localParticipant;
|
|
27
|
+
private _eventsController;
|
|
28
|
+
constructor({ protocol }: {
|
|
29
|
+
protocol: Protocol;
|
|
30
|
+
});
|
|
31
|
+
get localParticipant(): LocalParticipant | null;
|
|
32
|
+
get ready(): Promise<boolean>;
|
|
33
|
+
start(): Promise<void>;
|
|
34
|
+
dispose(): void;
|
|
35
|
+
sendRequest(type: string, request: RequestHeader, data?: Uint8Array): Promise<Response>;
|
|
36
|
+
private _handleResponse;
|
|
37
|
+
private _handleRoomReady;
|
|
38
|
+
private _onParticipantInit;
|
|
39
|
+
private _handleParticipant;
|
|
40
|
+
emit(event: RoomEvent): void;
|
|
41
|
+
listen(): AsyncIterable<RoomEvent>;
|
|
42
|
+
}
|
|
43
|
+
export {};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RoomClient = void 0;
|
|
4
|
+
const completer_1 = require("./completer");
|
|
5
|
+
const utils_1 = require("./utils");
|
|
6
|
+
const participant_1 = require("./participant");
|
|
7
|
+
const stream_controller_1 = require("./stream-controller");
|
|
8
|
+
const sync_client_1 = require("./sync-client");
|
|
9
|
+
const developer_client_1 = require("./developer-client");
|
|
10
|
+
const storage_client_1 = require("./storage-client");
|
|
11
|
+
const messaging_client_1 = require("./messaging-client");
|
|
12
|
+
const queues_client_1 = require("./queues-client");
|
|
13
|
+
const database_client_1 = require("./database-client");
|
|
14
|
+
const agent_client_1 = require("./agent-client");
|
|
15
|
+
const response_1 = require("./response");
|
|
16
|
+
class RoomClient {
|
|
17
|
+
constructor({ protocol }) {
|
|
18
|
+
this._pendingRequests = new Map();
|
|
19
|
+
this._ready = new completer_1.Completer();
|
|
20
|
+
this._localParticipant = null;
|
|
21
|
+
this._eventsController = new stream_controller_1.StreamController();
|
|
22
|
+
this.protocol = protocol;
|
|
23
|
+
protocol.addHandler("room_ready", this._handleRoomReady.bind(this));
|
|
24
|
+
protocol.addHandler("connected", this._handleParticipant.bind(this));
|
|
25
|
+
protocol.addHandler("__response__", this._handleResponse.bind(this));
|
|
26
|
+
this.sync = new sync_client_1.SyncClient({ room: this });
|
|
27
|
+
this.storage = new storage_client_1.StorageClient({ room: this });
|
|
28
|
+
this.developer = new developer_client_1.DeveloperClient({ room: this });
|
|
29
|
+
this.messaging = new messaging_client_1.MessagingClient({ room: this });
|
|
30
|
+
this.queues = new queues_client_1.QueuesClient({ room: this });
|
|
31
|
+
this.database = new database_client_1.DatabaseClient({ room: this });
|
|
32
|
+
this.agents = new agent_client_1.AgentsClient({ room: this });
|
|
33
|
+
}
|
|
34
|
+
get localParticipant() {
|
|
35
|
+
return this._localParticipant;
|
|
36
|
+
}
|
|
37
|
+
get ready() {
|
|
38
|
+
return this._ready.fut;
|
|
39
|
+
}
|
|
40
|
+
async start() {
|
|
41
|
+
this.sync.start();
|
|
42
|
+
await this.ready;
|
|
43
|
+
}
|
|
44
|
+
dispose() {
|
|
45
|
+
for (const prKey of this._pendingRequests.keys()) {
|
|
46
|
+
const pr = this._pendingRequests.get(prKey);
|
|
47
|
+
pr?.reject(new Error("Disposed"));
|
|
48
|
+
this._pendingRequests.delete(prKey);
|
|
49
|
+
}
|
|
50
|
+
this.sync.dispose();
|
|
51
|
+
this.protocol.dispose();
|
|
52
|
+
this._localParticipant = null;
|
|
53
|
+
}
|
|
54
|
+
async sendRequest(type, request, data) {
|
|
55
|
+
const requestId = this.protocol.getNextMessageId();
|
|
56
|
+
const pr = new completer_1.Completer();
|
|
57
|
+
this._pendingRequests.set(requestId, pr);
|
|
58
|
+
const message = (0, utils_1.packMessage)(request, data);
|
|
59
|
+
await this.protocol.send(type, message, requestId);
|
|
60
|
+
return await pr.fut;
|
|
61
|
+
}
|
|
62
|
+
async _handleResponse(protocol, messageId, type, data) {
|
|
63
|
+
if (!data) {
|
|
64
|
+
console.error("No data in response");
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const response = (0, response_1.unpackResponse)(data);
|
|
68
|
+
console.log("GOT RESPONSE", response);
|
|
69
|
+
if (!response) {
|
|
70
|
+
console.error("No response");
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (this._pendingRequests.has(messageId)) {
|
|
74
|
+
const pr = this._pendingRequests.get(messageId);
|
|
75
|
+
this._pendingRequests.delete(messageId);
|
|
76
|
+
if (response instanceof response_1.ErrorResponse) {
|
|
77
|
+
pr.reject(new Error(response.text));
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
pr.resolve(response);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
console.warn(`Received a response for a request that is not pending ${messageId}`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
async _handleRoomReady(protocol, messageId, type, data) {
|
|
88
|
+
this._ready.complete(JSON.parse(utils_1.decoder.decode(data))["room_name"]);
|
|
89
|
+
}
|
|
90
|
+
_onParticipantInit(participantId, attributes) {
|
|
91
|
+
this._localParticipant = new participant_1.LocalParticipant(this, participantId);
|
|
92
|
+
for (const k in attributes) {
|
|
93
|
+
this._localParticipant.setAttribute(k, attributes[k]);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
async _handleParticipant(protocol, messageId, type, data) {
|
|
97
|
+
const message = JSON.parse(utils_1.decoder.decode(data));
|
|
98
|
+
switch (message["type"]) {
|
|
99
|
+
case "init": this._onParticipantInit(message["participantId"], message["attributes"]);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
emit(event) {
|
|
103
|
+
this._eventsController.add(event);
|
|
104
|
+
}
|
|
105
|
+
listen() {
|
|
106
|
+
return this._eventsController.stream;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
exports.RoomClient = RoomClient;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
export declare abstract class RoomEvent {
|
|
2
|
+
abstract get name(): string;
|
|
3
|
+
abstract get description(): string;
|
|
4
|
+
}
|
|
5
|
+
export declare class RoomMessage {
|
|
6
|
+
fromParticipantId: string;
|
|
7
|
+
type: string;
|
|
8
|
+
message: Record<string, any>;
|
|
9
|
+
local: boolean;
|
|
10
|
+
attachment?: Uint8Array;
|
|
11
|
+
constructor({ fromParticipantId, type, message, local, attachment }: {
|
|
12
|
+
fromParticipantId: string;
|
|
13
|
+
type: string;
|
|
14
|
+
message: Record<string, any>;
|
|
15
|
+
local?: boolean;
|
|
16
|
+
attachment?: Uint8Array;
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
export declare class RoomMessageEvent extends RoomEvent {
|
|
20
|
+
message: RoomMessage;
|
|
21
|
+
constructor({ message }: {
|
|
22
|
+
message: RoomMessage;
|
|
23
|
+
});
|
|
24
|
+
get name(): string;
|
|
25
|
+
get description(): string;
|
|
26
|
+
}
|
|
27
|
+
export declare class FileCreatedEvent extends RoomEvent {
|
|
28
|
+
path: string;
|
|
29
|
+
constructor({ path }: {
|
|
30
|
+
path: string;
|
|
31
|
+
});
|
|
32
|
+
get name(): string;
|
|
33
|
+
get description(): string;
|
|
34
|
+
}
|
|
35
|
+
export declare class FileDeletedEvent extends RoomEvent {
|
|
36
|
+
path: string;
|
|
37
|
+
constructor({ path }: {
|
|
38
|
+
path: string;
|
|
39
|
+
});
|
|
40
|
+
get name(): string;
|
|
41
|
+
get description(): string;
|
|
42
|
+
}
|
|
43
|
+
export declare class FileUpdatedEvent extends RoomEvent {
|
|
44
|
+
path: string;
|
|
45
|
+
constructor({ path }: {
|
|
46
|
+
path: string;
|
|
47
|
+
});
|
|
48
|
+
get name(): string;
|
|
49
|
+
get description(): string;
|
|
50
|
+
}
|
|
51
|
+
export declare class RoomLogEvent extends RoomEvent {
|
|
52
|
+
type: string;
|
|
53
|
+
data: Record<string, any>;
|
|
54
|
+
constructor({ type, data }: {
|
|
55
|
+
type: string;
|
|
56
|
+
data: Record<string, any>;
|
|
57
|
+
});
|
|
58
|
+
get name(): string;
|
|
59
|
+
get description(): string;
|
|
60
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RoomLogEvent = exports.FileUpdatedEvent = exports.FileDeletedEvent = exports.FileCreatedEvent = exports.RoomMessageEvent = exports.RoomMessage = exports.RoomEvent = void 0;
|
|
4
|
+
class RoomEvent {
|
|
5
|
+
}
|
|
6
|
+
exports.RoomEvent = RoomEvent;
|
|
7
|
+
class RoomMessage {
|
|
8
|
+
constructor({ fromParticipantId, type, message, local = false, attachment }) {
|
|
9
|
+
this.fromParticipantId = fromParticipantId;
|
|
10
|
+
this.type = type;
|
|
11
|
+
this.message = message;
|
|
12
|
+
this.local = local;
|
|
13
|
+
this.attachment = attachment;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.RoomMessage = RoomMessage;
|
|
17
|
+
class RoomMessageEvent extends RoomEvent {
|
|
18
|
+
constructor({ message }) {
|
|
19
|
+
super();
|
|
20
|
+
this.message = message;
|
|
21
|
+
}
|
|
22
|
+
get name() {
|
|
23
|
+
return this.message.type;
|
|
24
|
+
}
|
|
25
|
+
get description() {
|
|
26
|
+
return `a message was received ${JSON.stringify(this.message.message)}`;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.RoomMessageEvent = RoomMessageEvent;
|
|
30
|
+
class FileCreatedEvent extends RoomEvent {
|
|
31
|
+
constructor({ path }) {
|
|
32
|
+
super();
|
|
33
|
+
this.path = path;
|
|
34
|
+
}
|
|
35
|
+
get name() {
|
|
36
|
+
return "file created";
|
|
37
|
+
}
|
|
38
|
+
get description() {
|
|
39
|
+
return `a file was created at the path ${this.path}`;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.FileCreatedEvent = FileCreatedEvent;
|
|
43
|
+
class FileDeletedEvent extends RoomEvent {
|
|
44
|
+
constructor({ path }) {
|
|
45
|
+
super();
|
|
46
|
+
this.path = path;
|
|
47
|
+
}
|
|
48
|
+
get name() {
|
|
49
|
+
return "file deleted";
|
|
50
|
+
}
|
|
51
|
+
get description() {
|
|
52
|
+
return `a file was deleted at the path ${this.path}`;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.FileDeletedEvent = FileDeletedEvent;
|
|
56
|
+
class FileUpdatedEvent extends RoomEvent {
|
|
57
|
+
constructor({ path }) {
|
|
58
|
+
super();
|
|
59
|
+
this.path = path;
|
|
60
|
+
}
|
|
61
|
+
get name() {
|
|
62
|
+
return "file updated";
|
|
63
|
+
}
|
|
64
|
+
get description() {
|
|
65
|
+
return `a file was updated at the path ${this.path}`;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.FileUpdatedEvent = FileUpdatedEvent;
|
|
69
|
+
class RoomLogEvent extends RoomEvent {
|
|
70
|
+
constructor({ type, data }) {
|
|
71
|
+
super();
|
|
72
|
+
this.type = type;
|
|
73
|
+
this.data = data;
|
|
74
|
+
}
|
|
75
|
+
get name() {
|
|
76
|
+
return this.type;
|
|
77
|
+
}
|
|
78
|
+
get description() {
|
|
79
|
+
return JSON.stringify(this.data);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.RoomLogEvent = RoomLogEvent;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { RuntimeDocument } from "./document";
|
|
2
|
+
import { MeshSchema } from "./schema";
|
|
3
|
+
export type Uint8List = Uint8Array;
|
|
4
|
+
export declare class RoomServerException extends Error {
|
|
5
|
+
constructor(message: string);
|
|
6
|
+
}
|
|
7
|
+
export declare class MeshDocument extends RuntimeDocument {
|
|
8
|
+
private _synchronized;
|
|
9
|
+
constructor({ schema, sendChangesToBackend }: {
|
|
10
|
+
schema: MeshSchema;
|
|
11
|
+
sendChangesToBackend?: (base64: string) => void;
|
|
12
|
+
});
|
|
13
|
+
onSendUpdateToBackend: (base64: string) => void;
|
|
14
|
+
onSendUpdateToClient: (base64: string) => void;
|
|
15
|
+
get synchronized(): Promise<boolean>;
|
|
16
|
+
get isSynchronized(): boolean;
|
|
17
|
+
setSynchronizedComplete(): void;
|
|
18
|
+
dispose(): void;
|
|
19
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MeshDocument = exports.RoomServerException = void 0;
|
|
4
|
+
const uuid_1 = require("uuid");
|
|
5
|
+
const document_1 = require("./document");
|
|
6
|
+
const completer_1 = require("./completer");
|
|
7
|
+
const runtime_1 = require("./runtime");
|
|
8
|
+
class RoomServerException extends Error {
|
|
9
|
+
constructor(message) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.name = "RoomServerException";
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.RoomServerException = RoomServerException;
|
|
15
|
+
class MeshDocument extends document_1.RuntimeDocument {
|
|
16
|
+
constructor({ schema, sendChangesToBackend }) {
|
|
17
|
+
super({
|
|
18
|
+
id: (0, uuid_1.v4)(),
|
|
19
|
+
schema,
|
|
20
|
+
sendChanges: (base64) => (0, runtime_1.applyChanges)(base64),
|
|
21
|
+
sendChangesToBackend,
|
|
22
|
+
});
|
|
23
|
+
this._synchronized = new completer_1.Completer();
|
|
24
|
+
this.onSendUpdateToBackend = (base64) => {
|
|
25
|
+
const parsed = JSON.parse(base64);
|
|
26
|
+
if (this.sendChangesToBackend) {
|
|
27
|
+
this.sendChangesToBackend(parsed.data);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
this.onSendUpdateToClient = (base64) => {
|
|
31
|
+
const parsed = JSON.parse(base64);
|
|
32
|
+
this.receiveChanges(parsed.data);
|
|
33
|
+
};
|
|
34
|
+
(0, runtime_1.registerDocument)(this.id, null, false, this.onSendUpdateToBackend, this.onSendUpdateToClient);
|
|
35
|
+
}
|
|
36
|
+
get synchronized() {
|
|
37
|
+
return this._synchronized.fut;
|
|
38
|
+
}
|
|
39
|
+
get isSynchronized() {
|
|
40
|
+
return this._synchronized.completed;
|
|
41
|
+
}
|
|
42
|
+
setSynchronizedComplete() {
|
|
43
|
+
this._synchronized.complete(true);
|
|
44
|
+
}
|
|
45
|
+
dispose() {
|
|
46
|
+
super.dispose();
|
|
47
|
+
(0, runtime_1.unregisterDocument)(this.id);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.MeshDocument = MeshDocument;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.unregisterDocument = exports.registerDocument = exports.applyChanges = exports.applyBackendChanges = void 0;
|
|
4
|
+
var entrypoint_js_1 = require("./entrypoint.js");
|
|
5
|
+
Object.defineProperty(exports, "applyBackendChanges", { enumerable: true, get: function () { return entrypoint_js_1.applyBackendChanges; } });
|
|
6
|
+
Object.defineProperty(exports, "applyChanges", { enumerable: true, get: function () { return entrypoint_js_1.applyChanges; } });
|
|
7
|
+
Object.defineProperty(exports, "registerDocument", { enumerable: true, get: function () { return entrypoint_js_1.registerDocument; } });
|
|
8
|
+
Object.defineProperty(exports, "unregisterDocument", { enumerable: true, get: function () { return entrypoint_js_1.unregisterDocument; } });
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
export declare class MeshSchemaValidationException extends Error {
|
|
2
|
+
constructor(message: string);
|
|
3
|
+
}
|
|
4
|
+
export declare enum SimpleValue {
|
|
5
|
+
number = "number",
|
|
6
|
+
string = "string",
|
|
7
|
+
nullValue = "null",
|
|
8
|
+
boolean = "boolean"
|
|
9
|
+
}
|
|
10
|
+
export declare namespace SimpleValue {
|
|
11
|
+
function fromString(val: string): SimpleValue | null;
|
|
12
|
+
}
|
|
13
|
+
export declare abstract class ElementProperty {
|
|
14
|
+
readonly name: string;
|
|
15
|
+
readonly description?: string;
|
|
16
|
+
constructor({ name, description }: {
|
|
17
|
+
name: string;
|
|
18
|
+
description?: string;
|
|
19
|
+
});
|
|
20
|
+
abstract validate(schema: MeshSchema): void;
|
|
21
|
+
abstract toJson(): Record<string, any>;
|
|
22
|
+
}
|
|
23
|
+
export declare class ValueProperty extends ElementProperty {
|
|
24
|
+
readonly type: SimpleValue;
|
|
25
|
+
readonly enumValues?: any[];
|
|
26
|
+
constructor({ name, description, type, enumValues }: {
|
|
27
|
+
name: string;
|
|
28
|
+
description?: string;
|
|
29
|
+
type: SimpleValue;
|
|
30
|
+
enumValues?: any[];
|
|
31
|
+
});
|
|
32
|
+
validate(_: MeshSchema): void;
|
|
33
|
+
toJson(): Record<string, any>;
|
|
34
|
+
}
|
|
35
|
+
export declare class ChildProperty extends ElementProperty {
|
|
36
|
+
private readonly _childTagNames;
|
|
37
|
+
readonly ordered: boolean;
|
|
38
|
+
constructor({ name, description, childTagNames, ordered }: {
|
|
39
|
+
name: string;
|
|
40
|
+
description?: string;
|
|
41
|
+
childTagNames: string[];
|
|
42
|
+
ordered?: boolean;
|
|
43
|
+
});
|
|
44
|
+
validate(schema: MeshSchema): void;
|
|
45
|
+
isTagAllowed(tagName: string): boolean;
|
|
46
|
+
get childTagNames(): string[];
|
|
47
|
+
toJson(): Record<string, any>;
|
|
48
|
+
}
|
|
49
|
+
export declare class ElementType {
|
|
50
|
+
private readonly _tagName;
|
|
51
|
+
private readonly _properties;
|
|
52
|
+
private readonly _description?;
|
|
53
|
+
private readonly _propertyLookup;
|
|
54
|
+
private _childPropertyName?;
|
|
55
|
+
constructor(params: {
|
|
56
|
+
tagName: string;
|
|
57
|
+
description?: string;
|
|
58
|
+
properties: ElementProperty[];
|
|
59
|
+
});
|
|
60
|
+
static fromJson(json: Record<string, any>): ElementType;
|
|
61
|
+
toJson(): Record<string, any>;
|
|
62
|
+
validate(schema: MeshSchema): void;
|
|
63
|
+
get childPropertyName(): string | undefined;
|
|
64
|
+
get tagName(): string;
|
|
65
|
+
get description(): string | undefined;
|
|
66
|
+
get properties(): ElementProperty[];
|
|
67
|
+
property(name: string): ElementProperty;
|
|
68
|
+
}
|
|
69
|
+
export declare class MeshSchema {
|
|
70
|
+
private readonly _rootTagName;
|
|
71
|
+
private readonly _elements;
|
|
72
|
+
readonly elementsByTagName: Record<string, ElementType>;
|
|
73
|
+
constructor(params: {
|
|
74
|
+
rootTagName: string;
|
|
75
|
+
elements: ElementType[];
|
|
76
|
+
});
|
|
77
|
+
static fromJson(json: Record<string, any>): MeshSchema;
|
|
78
|
+
toJson(): Record<string, any>;
|
|
79
|
+
element(name: string): ElementType;
|
|
80
|
+
validate(): void;
|
|
81
|
+
get root(): ElementType;
|
|
82
|
+
get elements(): ElementType[];
|
|
83
|
+
}
|