polfan-server-js-client 0.0.5
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/README.md +25 -0
- package/dist/Client.d.ts +76 -0
- package/dist/ObservableInterface.d.ts +9 -0
- package/dist/Token.d.ts +5 -0
- package/dist/connections/ConnectionInterface.d.ts +17 -0
- package/dist/connections/WebApiConnection.d.ts +15 -0
- package/dist/connections/WebSocketConnection.d.ts +19 -0
- package/dist/dtos/Dto.d.ts +16 -0
- package/dist/dtos/Message.d.ts +9 -0
- package/dist/dtos/Permission.d.ts +7 -0
- package/dist/dtos/Role.d.ts +7 -0
- package/dist/dtos/Room.d.ts +8 -0
- package/dist/dtos/RoomMember.d.ts +6 -0
- package/dist/dtos/RoomSummary.d.ts +7 -0
- package/dist/dtos/Space.d.ts +8 -0
- package/dist/dtos/SpaceMember.d.ts +7 -0
- package/dist/dtos/Topic.d.ts +7 -0
- package/dist/dtos/User.d.ts +9 -0
- package/dist/dtos/UserState.d.ts +8 -0
- package/dist/dtos/protocol/Envelope.d.ts +7 -0
- package/dist/dtos/protocol/EnvelopeMeta.d.ts +6 -0
- package/dist/dtos/protocol/ProtocolMessage.d.ts +7 -0
- package/dist/dtos/protocol/ProtocolMetaData.d.ts +6 -0
- package/dist/dtos/protocol/commands/AssignRole.d.ts +7 -0
- package/dist/dtos/protocol/commands/CreateMessage.d.ts +7 -0
- package/dist/dtos/protocol/commands/CreateRole.d.ts +7 -0
- package/dist/dtos/protocol/commands/CreateRoom.d.ts +7 -0
- package/dist/dtos/protocol/commands/CreateSpace.d.ts +5 -0
- package/dist/dtos/protocol/commands/CreateTopic.d.ts +7 -0
- package/dist/dtos/protocol/commands/DeassignRole.d.ts +7 -0
- package/dist/dtos/protocol/commands/DeleteRole.d.ts +6 -0
- package/dist/dtos/protocol/commands/DeleteRoom.d.ts +5 -0
- package/dist/dtos/protocol/commands/DeleteSpace.d.ts +5 -0
- package/dist/dtos/protocol/commands/DeleteTopic.d.ts +5 -0
- package/dist/dtos/protocol/commands/GetComputedPermissions.d.ts +8 -0
- package/dist/dtos/protocol/commands/GetRolePermissions.d.ts +8 -0
- package/dist/dtos/protocol/commands/GetRoomMembers.d.ts +5 -0
- package/dist/dtos/protocol/commands/GetSession.d.ts +4 -0
- package/dist/dtos/protocol/commands/GetSpaceMembers.d.ts +5 -0
- package/dist/dtos/protocol/commands/GetSpaceRooms.d.ts +5 -0
- package/dist/dtos/protocol/commands/GetUserPermissions.d.ts +8 -0
- package/dist/dtos/protocol/commands/JoinRoom.d.ts +5 -0
- package/dist/dtos/protocol/commands/JoinSpace.d.ts +5 -0
- package/dist/dtos/protocol/commands/LeaveRoom.d.ts +5 -0
- package/dist/dtos/protocol/commands/LeaveSpace.d.ts +5 -0
- package/dist/dtos/protocol/commands/SetRolePermissions.d.ts +9 -0
- package/dist/dtos/protocol/commands/SetUserPermissions.d.ts +9 -0
- package/dist/dtos/protocol/events/Bye.d.ts +5 -0
- package/dist/dtos/protocol/events/Error.d.ts +6 -0
- package/dist/dtos/protocol/events/NewMessage.d.ts +6 -0
- package/dist/dtos/protocol/events/NewRole.d.ts +7 -0
- package/dist/dtos/protocol/events/NewRoom.d.ts +7 -0
- package/dist/dtos/protocol/events/NewTopic.d.ts +7 -0
- package/dist/dtos/protocol/events/Ok.d.ts +4 -0
- package/dist/dtos/protocol/events/Permissions.d.ts +6 -0
- package/dist/dtos/protocol/events/RoleDeleted.d.ts +6 -0
- package/dist/dtos/protocol/events/RoomDeleted.d.ts +5 -0
- package/dist/dtos/protocol/events/RoomJoined.d.ts +6 -0
- package/dist/dtos/protocol/events/RoomLeft.d.ts +5 -0
- package/dist/dtos/protocol/events/RoomMemberJoined.d.ts +6 -0
- package/dist/dtos/protocol/events/RoomMemberLeft.d.ts +5 -0
- package/dist/dtos/protocol/events/RoomMembers.d.ts +6 -0
- package/dist/dtos/protocol/events/Session.d.ts +9 -0
- package/dist/dtos/protocol/events/SpaceDeleted.d.ts +5 -0
- package/dist/dtos/protocol/events/SpaceJoined.d.ts +6 -0
- package/dist/dtos/protocol/events/SpaceLeft.d.ts +5 -0
- package/dist/dtos/protocol/events/SpaceMemberJoined.d.ts +6 -0
- package/dist/dtos/protocol/events/SpaceMemberLeft.d.ts +5 -0
- package/dist/dtos/protocol/events/SpaceMemberUpdate.d.ts +6 -0
- package/dist/dtos/protocol/events/SpaceMembers.d.ts +6 -0
- package/dist/dtos/protocol/events/SpaceRooms.d.ts +6 -0
- package/dist/dtos/protocol/events/TopicDeleted.d.ts +5 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +1916 -0
- package/dist/index.js.map +1 -0
- package/dist/protocol.d.ts +7 -0
- package/dist/pserv-js-client.js +2 -0
- package/dist/pserv-js-client.js.map +1 -0
- package/package.json +22 -0
- package/src/Client.ts +166 -0
- package/src/ObservableInterface.ts +22 -0
- package/src/Token.ts +21 -0
- package/src/connections/ConnectionInterface.ts +20 -0
- package/src/connections/WebApiConnection.ts +43 -0
- package/src/connections/WebSocketConnection.ts +47 -0
- package/src/dtos/Dto.ts +45 -0
- package/src/dtos/Message.ts +16 -0
- package/src/dtos/Permission.ts +12 -0
- package/src/dtos/Role.ts +12 -0
- package/src/dtos/Room.ts +15 -0
- package/src/dtos/RoomMember.ts +13 -0
- package/src/dtos/RoomSummary.ts +12 -0
- package/src/dtos/Space.ts +15 -0
- package/src/dtos/SpaceMember.ts +14 -0
- package/src/dtos/Topic.ts +12 -0
- package/src/dtos/User.ts +15 -0
- package/src/dtos/UserState.ts +16 -0
- package/src/dtos/protocol/Envelope.ts +14 -0
- package/src/dtos/protocol/EnvelopeMeta.ts +11 -0
- package/src/dtos/protocol/commands/AssignRole.ts +12 -0
- package/src/dtos/protocol/commands/CreateMessage.ts +12 -0
- package/src/dtos/protocol/commands/CreateRole.ts +12 -0
- package/src/dtos/protocol/commands/CreateRoom.ts +12 -0
- package/src/dtos/protocol/commands/CreateSpace.ts +10 -0
- package/src/dtos/protocol/commands/CreateTopic.ts +12 -0
- package/src/dtos/protocol/commands/DeassignRole.ts +12 -0
- package/src/dtos/protocol/commands/DeleteRole.ts +11 -0
- package/src/dtos/protocol/commands/DeleteRoom.ts +10 -0
- package/src/dtos/protocol/commands/DeleteSpace.ts +10 -0
- package/src/dtos/protocol/commands/DeleteTopic.ts +10 -0
- package/src/dtos/protocol/commands/GetComputedPermissions.ts +13 -0
- package/src/dtos/protocol/commands/GetRolePermissions.ts +13 -0
- package/src/dtos/protocol/commands/GetRoomMembers.ts +10 -0
- package/src/dtos/protocol/commands/GetSession.ts +8 -0
- package/src/dtos/protocol/commands/GetSpaceMembers.ts +10 -0
- package/src/dtos/protocol/commands/GetSpaceRooms.ts +10 -0
- package/src/dtos/protocol/commands/GetUserPermissions.ts +13 -0
- package/src/dtos/protocol/commands/JoinRoom.ts +10 -0
- package/src/dtos/protocol/commands/JoinSpace.ts +10 -0
- package/src/dtos/protocol/commands/LeaveRoom.ts +10 -0
- package/src/dtos/protocol/commands/LeaveSpace.ts +10 -0
- package/src/dtos/protocol/commands/SetRolePermissions.ts +16 -0
- package/src/dtos/protocol/commands/SetUserPermissions.ts +16 -0
- package/src/dtos/protocol/events/Bye.ts +10 -0
- package/src/dtos/protocol/events/Error.ts +11 -0
- package/src/dtos/protocol/events/NewMessage.ts +13 -0
- package/src/dtos/protocol/events/NewRole.ts +14 -0
- package/src/dtos/protocol/events/NewRoom.ts +14 -0
- package/src/dtos/protocol/events/NewTopic.ts +14 -0
- package/src/dtos/protocol/events/Ok.ts +8 -0
- package/src/dtos/protocol/events/Permissions.ts +13 -0
- package/src/dtos/protocol/events/RoleDeleted.ts +11 -0
- package/src/dtos/protocol/events/RoomDeleted.ts +10 -0
- package/src/dtos/protocol/events/RoomJoined.ts +13 -0
- package/src/dtos/protocol/events/RoomLeft.ts +10 -0
- package/src/dtos/protocol/events/RoomMemberJoined.ts +13 -0
- package/src/dtos/protocol/events/RoomMemberLeft.ts +10 -0
- package/src/dtos/protocol/events/RoomMembers.ts +13 -0
- package/src/dtos/protocol/events/Session.ts +17 -0
- package/src/dtos/protocol/events/SpaceDeleted.ts +10 -0
- package/src/dtos/protocol/events/SpaceJoined.ts +13 -0
- package/src/dtos/protocol/events/SpaceLeft.ts +10 -0
- package/src/dtos/protocol/events/SpaceMemberJoined.ts +13 -0
- package/src/dtos/protocol/events/SpaceMemberLeft.ts +10 -0
- package/src/dtos/protocol/events/SpaceMemberUpdate.ts +13 -0
- package/src/dtos/protocol/events/SpaceMembers.ts +13 -0
- package/src/dtos/protocol/events/SpaceRooms.ts +13 -0
- package/src/dtos/protocol/events/TopicDeleted.ts +10 -0
- package/src/index.ts +26 -0
- package/src/protocol.ts +113 -0
- package/tsconfig.json +12 -0
- package/webpack.config.js +24 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type EventHandler<T = any> = (...args: T[]) => void;
|
|
2
|
+
|
|
3
|
+
export interface ObservableInterface {
|
|
4
|
+
on(eventName: string, handler: EventHandler): ObservableInterface;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export abstract class EventTarget implements ObservableInterface {
|
|
8
|
+
protected events: Map<string, EventHandler[]> = new Map<string, EventHandler[]>();
|
|
9
|
+
|
|
10
|
+
public on(eventName: string, handler: EventHandler): EventTarget {
|
|
11
|
+
const handlers = this.events.get(eventName) ?? [];
|
|
12
|
+
handlers.push(handler);
|
|
13
|
+
this.events.set(eventName, handlers);
|
|
14
|
+
return this;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public emit(eventName: string, ...args: any): EventTarget
|
|
18
|
+
{
|
|
19
|
+
this.events.get(eventName)?.forEach(callback => callback(...args));
|
|
20
|
+
return this;
|
|
21
|
+
}
|
|
22
|
+
}
|
package/src/Token.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const apiUrl = 'https://polfan.pl/webservice/api/auth/token';
|
|
2
|
+
const defaultClientName = 'Polfan JS Library';
|
|
3
|
+
|
|
4
|
+
export interface TokenInterface {
|
|
5
|
+
token: string,
|
|
6
|
+
expiration: string
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export async function getToken(login: string, password: string, clientName: string = defaultClientName): Promise<TokenInterface> {
|
|
10
|
+
const response = await fetch(apiUrl, {
|
|
11
|
+
method: 'POST',
|
|
12
|
+
headers: {
|
|
13
|
+
'Content-Type': 'application/json',
|
|
14
|
+
Accept: 'application/json'
|
|
15
|
+
},
|
|
16
|
+
body: JSON.stringify({
|
|
17
|
+
login, password, client_name: clientName
|
|
18
|
+
})
|
|
19
|
+
});
|
|
20
|
+
return response.json();
|
|
21
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import {ObservableInterface} from "../ObservableInterface";
|
|
2
|
+
|
|
3
|
+
export enum ConnectionState {
|
|
4
|
+
pending,
|
|
5
|
+
ready,
|
|
6
|
+
disconnected
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export enum ConnectionEvent {
|
|
10
|
+
message = 'message',
|
|
11
|
+
connect = 'connect',
|
|
12
|
+
disconnect = 'disconnect'
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface ConnectionInterface extends ObservableInterface {
|
|
16
|
+
state: ConnectionState,
|
|
17
|
+
connect(): void;
|
|
18
|
+
disconnect(): void;
|
|
19
|
+
send(data: string): void;
|
|
20
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import {ConnectionEvent, ConnectionInterface, ConnectionState} from "./ConnectionInterface";
|
|
2
|
+
import {EventTarget} from "../ObservableInterface";
|
|
3
|
+
|
|
4
|
+
export interface WebApiConnectionConfig {
|
|
5
|
+
token: string;
|
|
6
|
+
url: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export class WebApiConnection extends EventTarget implements ConnectionInterface {
|
|
10
|
+
public state: ConnectionState = ConnectionState.ready;
|
|
11
|
+
|
|
12
|
+
public constructor(
|
|
13
|
+
private readonly config: WebApiConnectionConfig
|
|
14
|
+
) {
|
|
15
|
+
super();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
public connect(): void {
|
|
19
|
+
this.emit(ConnectionEvent.connect);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public disconnect(): void {
|
|
23
|
+
this.emit(ConnectionEvent.disconnect);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public send(data: string): void {
|
|
27
|
+
fetch(this.config.url, {
|
|
28
|
+
method: 'POST',
|
|
29
|
+
headers: {
|
|
30
|
+
Authorization: `Bearer ${this.config.token}`,
|
|
31
|
+
ContentType: 'application/json',
|
|
32
|
+
Accept: 'application/json'
|
|
33
|
+
},
|
|
34
|
+
body: JSON.stringify(data)
|
|
35
|
+
})
|
|
36
|
+
.then((response: Response) => response.text())
|
|
37
|
+
.then(this.onMessage);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
private onMessage(message: string): void {
|
|
41
|
+
this.emit(ConnectionEvent.message, message);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import {EventTarget} from "../ObservableInterface";
|
|
2
|
+
import {ConnectionEvent, ConnectionInterface, ConnectionState} from "./ConnectionInterface";
|
|
3
|
+
|
|
4
|
+
interface WebSocketConnectionConfig {
|
|
5
|
+
url: string;
|
|
6
|
+
token: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export class WebSocketConnection extends EventTarget implements ConnectionInterface {
|
|
10
|
+
public state: ConnectionState = ConnectionState.disconnected;
|
|
11
|
+
|
|
12
|
+
private ws: WebSocket|null = null;
|
|
13
|
+
|
|
14
|
+
public constructor(private config: WebSocketConnectionConfig) {
|
|
15
|
+
super();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
public connect(): void {
|
|
19
|
+
this.ws = new WebSocket(`${this.config.url}?token=${this.config.token}`);
|
|
20
|
+
this.ws.onopen = () => this.onOpen();
|
|
21
|
+
this.ws.onclose = () => this.onClose();
|
|
22
|
+
this.ws.onerror = () => this.onClose();
|
|
23
|
+
this.ws.onmessage = ev => this.onMessage(ev);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public disconnect(): void {
|
|
27
|
+
this.ws?.close();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public send(data: string): void {
|
|
31
|
+
this.ws?.send(data);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
private onMessage(event: MessageEvent): void {
|
|
35
|
+
this.emit(ConnectionEvent.message, event.data);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
private onClose(): void {
|
|
39
|
+
this.state = ConnectionState.disconnected;
|
|
40
|
+
this.emit(ConnectionEvent.disconnect);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
private onOpen(): void {
|
|
44
|
+
this.state = ConnectionState.ready;
|
|
45
|
+
this.emit(ConnectionEvent.connect);
|
|
46
|
+
}
|
|
47
|
+
}
|
package/src/dtos/Dto.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export function cast<T extends typeof Dto>(data: any, dto: T): T {
|
|
2
|
+
if (data instanceof dto) {
|
|
3
|
+
return data as any;
|
|
4
|
+
}
|
|
5
|
+
return new (dto as any)(data);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function castArray<T extends typeof Dto>(data: any[], dto: T): T[] {
|
|
9
|
+
if (!Array.isArray(data)) throw new Error(`Passed data is not an array of ${dto.name}`);
|
|
10
|
+
return data.map(item => cast(item, dto));
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
type ExcludeMethods<T> = Pick<T, { [K in keyof T]: T[K] extends Function ? never : K }[keyof T]>;
|
|
14
|
+
export type DtoData<T> = { [K in keyof ExcludeMethods<T>]: any };
|
|
15
|
+
|
|
16
|
+
export abstract class Dto {
|
|
17
|
+
public constructor(...args: any[]) {
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public toJson(overrideBy: any = {}): string {
|
|
21
|
+
return JSON.stringify(this.toRaw(overrideBy));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public toRaw(overrideBy: any = {}): DtoData<this> {
|
|
25
|
+
const object: {[key: string]: any} = {};
|
|
26
|
+
Object.keys(this).forEach(key => {
|
|
27
|
+
if (overrideBy.hasOwnProperty(key)) {
|
|
28
|
+
object[key] = overrideBy[key];
|
|
29
|
+
} else if ((this as any)[key] instanceof Dto) {
|
|
30
|
+
object[key] = (this as any)[key].toRaw();
|
|
31
|
+
} else {
|
|
32
|
+
object[key] = (this as any)[key]
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
return object as DtoData<this>;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
public clone(overrideBy: any = {}): this {
|
|
39
|
+
return new (this.constructor as any)(this.toRaw(overrideBy));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
protected fill(data: any, overrideBy: any = {}) {
|
|
43
|
+
Object.assign(this, {...data, ...overrideBy});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {cast, Dto, DtoData} from "./Dto";
|
|
2
|
+
import {User} from "./User";
|
|
3
|
+
|
|
4
|
+
export class Message extends Dto {
|
|
5
|
+
public readonly id: string;
|
|
6
|
+
public readonly author: User;
|
|
7
|
+
public readonly topicId: string;
|
|
8
|
+
public readonly content: string;
|
|
9
|
+
|
|
10
|
+
public constructor(data: DtoData<Message>) {
|
|
11
|
+
super();
|
|
12
|
+
this.fill(data, {
|
|
13
|
+
author: cast(data.author, User),
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {Dto, DtoData} from "./Dto";
|
|
2
|
+
|
|
3
|
+
export class Permission extends Dto {
|
|
4
|
+
public readonly name: string;
|
|
5
|
+
public readonly value: boolean;
|
|
6
|
+
public readonly skip: boolean;
|
|
7
|
+
|
|
8
|
+
public constructor(data: DtoData<Permission>) {
|
|
9
|
+
super(data);
|
|
10
|
+
this.fill(data);
|
|
11
|
+
}
|
|
12
|
+
}
|
package/src/dtos/Role.ts
ADDED
package/src/dtos/Room.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {castArray, Dto, DtoData} from "./Dto";
|
|
2
|
+
import {Topic} from "./Topic";
|
|
3
|
+
|
|
4
|
+
export class Room extends Dto {
|
|
5
|
+
public readonly id: string;
|
|
6
|
+
public readonly name: string;
|
|
7
|
+
public readonly topics: Topic[];
|
|
8
|
+
|
|
9
|
+
public constructor(data: DtoData<Room>) {
|
|
10
|
+
super();
|
|
11
|
+
this.fill(data, {
|
|
12
|
+
topics: castArray(data.topics, Topic),
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import {cast, Dto, DtoData} from "./Dto";
|
|
2
|
+
import {User} from "./User";
|
|
3
|
+
|
|
4
|
+
export class RoomMember extends Dto {
|
|
5
|
+
public readonly user: User;
|
|
6
|
+
|
|
7
|
+
public constructor(data: DtoData<RoomMember>) {
|
|
8
|
+
super();
|
|
9
|
+
this.fill(data, {
|
|
10
|
+
user: cast(data.user, User),
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {Dto, DtoData} from "./Dto";
|
|
2
|
+
|
|
3
|
+
export class RoomSummary extends Dto {
|
|
4
|
+
public readonly id: string;
|
|
5
|
+
public readonly name: string;
|
|
6
|
+
public readonly description: string;
|
|
7
|
+
|
|
8
|
+
public constructor(data: DtoData<RoomSummary>) {
|
|
9
|
+
super();
|
|
10
|
+
this.fill(data);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {castArray, Dto, DtoData} from "./Dto";
|
|
2
|
+
import {Role} from "./Role";
|
|
3
|
+
|
|
4
|
+
export class Space extends Dto {
|
|
5
|
+
public readonly id: string;
|
|
6
|
+
public readonly name: string;
|
|
7
|
+
public readonly roles: Role[];
|
|
8
|
+
|
|
9
|
+
public constructor(data: DtoData<Space>) {
|
|
10
|
+
super();
|
|
11
|
+
this.fill(data, {
|
|
12
|
+
roles: castArray(data.roles, Role)
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import {castArray, Dto, DtoData} from "./Dto";
|
|
2
|
+
import {User} from "./User";
|
|
3
|
+
|
|
4
|
+
export class SpaceMember extends Dto {
|
|
5
|
+
public readonly user: User;
|
|
6
|
+
public readonly roles: string[];
|
|
7
|
+
|
|
8
|
+
public constructor(data: DtoData<SpaceMember>) {
|
|
9
|
+
super();
|
|
10
|
+
this.fill(data, {
|
|
11
|
+
user: castArray(data.user, User),
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {Dto, DtoData} from "./Dto";
|
|
2
|
+
|
|
3
|
+
export class Topic extends Dto {
|
|
4
|
+
public readonly id: string;
|
|
5
|
+
public readonly name: string;
|
|
6
|
+
public readonly description: string;
|
|
7
|
+
|
|
8
|
+
public constructor(data: DtoData<Topic>) {
|
|
9
|
+
super();
|
|
10
|
+
this.fill(data);
|
|
11
|
+
}
|
|
12
|
+
}
|
package/src/dtos/User.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {Dto, DtoData} from "./Dto";
|
|
2
|
+
|
|
3
|
+
export type UserFlag = 'bot' | 'temp';
|
|
4
|
+
|
|
5
|
+
export class User extends Dto {
|
|
6
|
+
public readonly id: string;
|
|
7
|
+
public readonly nick: string;
|
|
8
|
+
public readonly avatar: string;
|
|
9
|
+
public readonly flags: UserFlag[];
|
|
10
|
+
|
|
11
|
+
public constructor(data: DtoData<User>) {
|
|
12
|
+
super();
|
|
13
|
+
this.fill(data);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {Space} from "./Space";
|
|
2
|
+
import {Room} from "./Room";
|
|
3
|
+
import {castArray, Dto, DtoData} from "./Dto";
|
|
4
|
+
|
|
5
|
+
export class UserState extends Dto {
|
|
6
|
+
public readonly spaces: Space[];
|
|
7
|
+
public readonly rooms: Room[];
|
|
8
|
+
|
|
9
|
+
public constructor(data: DtoData<UserState>) {
|
|
10
|
+
super();
|
|
11
|
+
this.fill(data, {
|
|
12
|
+
spaces: castArray(data.spaces, Space),
|
|
13
|
+
rooms: castArray(data.rooms, Room),
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import {cast, Dto, DtoData} from "../Dto";
|
|
2
|
+
import {EnvelopeMeta} from "./EnvelopeMeta";
|
|
3
|
+
|
|
4
|
+
export class Envelope<T = any> extends Dto {
|
|
5
|
+
public readonly meta: EnvelopeMeta;
|
|
6
|
+
public readonly data: T;
|
|
7
|
+
|
|
8
|
+
public constructor(data: DtoData<Envelope>) {
|
|
9
|
+
super();
|
|
10
|
+
this.fill(data, {
|
|
11
|
+
meta: cast(data.meta, EnvelopeMeta),
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {Dto, DtoData} from "../../Dto";
|
|
2
|
+
|
|
3
|
+
export class AssignRole extends Dto {
|
|
4
|
+
public readonly roleId: string;
|
|
5
|
+
public readonly spaceId: string;
|
|
6
|
+
public readonly userId: string;
|
|
7
|
+
|
|
8
|
+
public constructor(data: DtoData<AssignRole>) {
|
|
9
|
+
super();
|
|
10
|
+
this.fill(data);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {Dto, DtoData} from "../../Dto";
|
|
2
|
+
import {Message} from "../../Message";
|
|
3
|
+
|
|
4
|
+
export class CreateMessage extends Dto {
|
|
5
|
+
public readonly topicId: string;
|
|
6
|
+
public readonly content: string;
|
|
7
|
+
|
|
8
|
+
public constructor(data: DtoData<Message>) {
|
|
9
|
+
super();
|
|
10
|
+
this.fill(data);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {Dto, DtoData} from "../../Dto";
|
|
2
|
+
|
|
3
|
+
export class CreateRole extends Dto {
|
|
4
|
+
public readonly spaceId: string;
|
|
5
|
+
public readonly name: string;
|
|
6
|
+
public readonly color: string;
|
|
7
|
+
|
|
8
|
+
public constructor(data: DtoData<CreateRole>) {
|
|
9
|
+
super();
|
|
10
|
+
this.fill(data);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {Dto, DtoData} from "../../Dto";
|
|
2
|
+
|
|
3
|
+
export class CreateRoom extends Dto {
|
|
4
|
+
public readonly spaceId: string;
|
|
5
|
+
public readonly name: string;
|
|
6
|
+
public readonly description: string;
|
|
7
|
+
|
|
8
|
+
public constructor(data: DtoData<CreateRoom>) {
|
|
9
|
+
super();
|
|
10
|
+
this.fill(data);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {Dto, DtoData} from "../../Dto";
|
|
2
|
+
|
|
3
|
+
export class CreateTopic extends Dto {
|
|
4
|
+
public readonly roomId: string;
|
|
5
|
+
public readonly name: string;
|
|
6
|
+
public readonly description: string;
|
|
7
|
+
|
|
8
|
+
public constructor(data: DtoData<CreateTopic>) {
|
|
9
|
+
super();
|
|
10
|
+
this.fill(data);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {Dto, DtoData} from "../../Dto";
|
|
2
|
+
|
|
3
|
+
export class DeassignRole extends Dto {
|
|
4
|
+
public readonly roleId: string;
|
|
5
|
+
public readonly spaceId: string;
|
|
6
|
+
public readonly userId: string;
|
|
7
|
+
|
|
8
|
+
public constructor(data: DtoData<DeassignRole>) {
|
|
9
|
+
super();
|
|
10
|
+
this.fill(data);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import {Dto, DtoData} from "../../Dto";
|
|
2
|
+
|
|
3
|
+
export class GetComputedPermissions extends Dto {
|
|
4
|
+
public readonly names: string[] | null | undefined;
|
|
5
|
+
public readonly spaceId: string;
|
|
6
|
+
public readonly roomId: string;
|
|
7
|
+
public readonly topicId: string;
|
|
8
|
+
|
|
9
|
+
public constructor(data: DtoData<GetComputedPermissions>) {
|
|
10
|
+
super();
|
|
11
|
+
this.fill(data);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import {Dto, DtoData} from "../../Dto";
|
|
2
|
+
|
|
3
|
+
export class GetRolePermissions extends Dto {
|
|
4
|
+
public readonly layer: 'Space' | 'Room' | 'Topic';
|
|
5
|
+
public readonly layerId: string;
|
|
6
|
+
public readonly roleId: string;
|
|
7
|
+
public readonly names: string[] | null | undefined;
|
|
8
|
+
|
|
9
|
+
public constructor(data: DtoData<GetRolePermissions>) {
|
|
10
|
+
super();
|
|
11
|
+
this.fill(data);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import {Dto, DtoData} from "../../Dto";
|
|
2
|
+
|
|
3
|
+
export class GetUserPermissions extends Dto {
|
|
4
|
+
public readonly layer: 'Global' | 'Space' | 'Room' | 'Topic';
|
|
5
|
+
public readonly layerId: string;
|
|
6
|
+
public readonly userId: string;
|
|
7
|
+
public readonly names: string[] | null | undefined;
|
|
8
|
+
|
|
9
|
+
public constructor(data: DtoData<GetUserPermissions>) {
|
|
10
|
+
super();
|
|
11
|
+
this.fill(data);
|
|
12
|
+
}
|
|
13
|
+
}
|