@omujs/chat 0.9.47 → 0.9.49
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/dts/chat.d.ts +20 -0
- package/dist/dts/const.d.ts +2 -0
- package/dist/dts/event/event-types.d.ts +15 -0
- package/dist/dts/event/event.d.ts +33 -0
- package/{src/event/index.ts → dist/dts/event/index.d.ts} +0 -1
- package/dist/dts/models/author.d.ts +37 -0
- package/dist/dts/models/channel.d.ts +31 -0
- package/dist/dts/models/content.d.ts +24 -0
- package/dist/dts/models/gift.d.ts +23 -0
- package/{src/models/index.ts → dist/dts/models/index.d.ts} +0 -1
- package/dist/dts/models/message.d.ts +40 -0
- package/dist/dts/models/paid.d.ts +11 -0
- package/dist/dts/models/provider.d.ts +34 -0
- package/dist/dts/models/reaction.d.ts +21 -0
- package/dist/dts/models/role.d.ts +26 -0
- package/dist/dts/models/room.d.ts +44 -0
- package/dist/dts/models/vote.d.ts +33 -0
- package/dist/dts/permissions.d.ts +7 -0
- package/dist/esm/chat.js +7976 -0
- package/dist/esm/const.js +5060 -0
- package/dist/esm/event/event-types.js +76 -0
- package/dist/esm/event/event.js +106 -0
- package/dist/esm/event/index.js +115 -0
- package/dist/esm/index.js +8022 -0
- package/dist/esm/models/author.js +5136 -0
- package/dist/esm/models/channel.js +5102 -0
- package/dist/esm/models/content.js +39 -0
- package/dist/esm/models/gift.js +40 -0
- package/dist/esm/models/index.js +5499 -0
- package/dist/esm/models/message.js +5199 -0
- package/dist/esm/models/paid.js +25 -0
- package/dist/esm/models/provider.js +5106 -0
- package/dist/esm/models/reaction.js +5079 -0
- package/dist/esm/models/role.js +44 -0
- package/dist/esm/models/room.js +5102 -0
- package/dist/esm/models/vote.js +5098 -0
- package/dist/esm/permissions.js +5073 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +28 -25
- package/CHANGELOG.md +0 -1823
- package/src/chat.ts +0 -131
- package/src/const.ts +0 -3
- package/src/event/event-types.ts +0 -16
- package/src/event/event.ts +0 -102
- package/src/models/author.ts +0 -72
- package/src/models/channel.ts +0 -67
- package/src/models/content.ts +0 -62
- package/src/models/gift.ts +0 -49
- package/src/models/message.ts +0 -88
- package/src/models/paid.ts +0 -22
- package/src/models/provider.ts +0 -73
- package/src/models/reaction.ts +0 -39
- package/src/models/role.ts +0 -55
- package/src/models/room.ts +0 -82
- package/src/models/vote.ts +0 -67
- package/src/permissions.ts +0 -9
- package/tsconfig.json +0 -15
- /package/{src/index.ts → dist/dts/index.d.ts} +0 -0
package/src/chat.ts
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import type { Omu } from '@omujs/omu';
|
|
2
|
-
import { Serializer } from '@omujs/omu';
|
|
3
|
-
import { EndpointType } from '@omujs/omu/api/endpoint';
|
|
4
|
-
import type { Signal } from '@omujs/omu/api/signal';
|
|
5
|
-
import { SignalType } from '@omujs/omu/api/signal';
|
|
6
|
-
import type { Table } from '@omujs/omu/api/table';
|
|
7
|
-
import { TableType } from '@omujs/omu/api/table';
|
|
8
|
-
|
|
9
|
-
import { PLUGIN_ID } from './const';
|
|
10
|
-
import type { EventHandler, EventSource } from './event';
|
|
11
|
-
import { EventRegistry } from './event';
|
|
12
|
-
import { Author, Channel, Message, Provider, Reaction, Room, Vote } from './models';
|
|
13
|
-
import {
|
|
14
|
-
CHAT_CHANNEL_TREE_PERMISSION_ID,
|
|
15
|
-
CHAT_PERMISSION_ID,
|
|
16
|
-
CHAT_READ_PERMISSION_ID,
|
|
17
|
-
CHAT_WRITE_PERMISSION_ID,
|
|
18
|
-
} from './permissions';
|
|
19
|
-
|
|
20
|
-
const MESSAGE_TABLE_TYPE = TableType.createJson(PLUGIN_ID, {
|
|
21
|
-
name: 'messages',
|
|
22
|
-
serializer: Message,
|
|
23
|
-
key: (item) => item.key(),
|
|
24
|
-
permissions: {
|
|
25
|
-
all: CHAT_PERMISSION_ID,
|
|
26
|
-
read: CHAT_READ_PERMISSION_ID,
|
|
27
|
-
write: CHAT_WRITE_PERMISSION_ID,
|
|
28
|
-
},
|
|
29
|
-
});
|
|
30
|
-
const AUTHOR_TABLE_TYPE = TableType.createJson(PLUGIN_ID, {
|
|
31
|
-
name: 'authors',
|
|
32
|
-
serializer: Author,
|
|
33
|
-
key: (item) => item.key(),
|
|
34
|
-
permissions: {
|
|
35
|
-
all: CHAT_PERMISSION_ID,
|
|
36
|
-
read: CHAT_READ_PERMISSION_ID,
|
|
37
|
-
write: CHAT_WRITE_PERMISSION_ID,
|
|
38
|
-
},
|
|
39
|
-
});
|
|
40
|
-
const CHANNEL_TABLE_TYPE = TableType.createJson(PLUGIN_ID, {
|
|
41
|
-
name: 'channels',
|
|
42
|
-
serializer: Channel,
|
|
43
|
-
key: (item) => item.key(),
|
|
44
|
-
permissions: {
|
|
45
|
-
all: CHAT_PERMISSION_ID,
|
|
46
|
-
read: CHAT_READ_PERMISSION_ID,
|
|
47
|
-
write: CHAT_WRITE_PERMISSION_ID,
|
|
48
|
-
},
|
|
49
|
-
});
|
|
50
|
-
const PROVIDER_TABLE_TYPE = TableType.createJson(PLUGIN_ID, {
|
|
51
|
-
name: 'providers',
|
|
52
|
-
serializer: Provider,
|
|
53
|
-
key: (item) => item.key(),
|
|
54
|
-
permissions: {
|
|
55
|
-
all: CHAT_PERMISSION_ID,
|
|
56
|
-
read: CHAT_READ_PERMISSION_ID,
|
|
57
|
-
write: CHAT_WRITE_PERMISSION_ID,
|
|
58
|
-
},
|
|
59
|
-
});
|
|
60
|
-
const ROOM_TABLE_TYPE = TableType.createJson(PLUGIN_ID, {
|
|
61
|
-
name: 'rooms',
|
|
62
|
-
serializer: Room,
|
|
63
|
-
key: (item) => item.key(),
|
|
64
|
-
permissions: {
|
|
65
|
-
all: CHAT_PERMISSION_ID,
|
|
66
|
-
read: CHAT_READ_PERMISSION_ID,
|
|
67
|
-
write: CHAT_WRITE_PERMISSION_ID,
|
|
68
|
-
},
|
|
69
|
-
});
|
|
70
|
-
const VOTE_TABLE_TYPE = TableType.createJson(PLUGIN_ID, {
|
|
71
|
-
name: 'votes',
|
|
72
|
-
serializer: Vote,
|
|
73
|
-
key: (item) => item.key(),
|
|
74
|
-
permissions: {
|
|
75
|
-
all: CHAT_PERMISSION_ID,
|
|
76
|
-
read: CHAT_READ_PERMISSION_ID,
|
|
77
|
-
write: CHAT_WRITE_PERMISSION_ID,
|
|
78
|
-
},
|
|
79
|
-
});
|
|
80
|
-
const CREATE_CHANNEL_TREE_ENDPOINT = EndpointType.createJson(PLUGIN_ID, {
|
|
81
|
-
name: 'create_channel_tree',
|
|
82
|
-
requestSerializer: Serializer.noop<string>(),
|
|
83
|
-
responseSerializer: Serializer.of(Channel).toArray(),
|
|
84
|
-
permissionId: CHAT_CHANNEL_TREE_PERMISSION_ID,
|
|
85
|
-
});
|
|
86
|
-
const REACTION_SIGNAL = SignalType.createJson(PLUGIN_ID, {
|
|
87
|
-
name: 'reaction',
|
|
88
|
-
serializer: Reaction,
|
|
89
|
-
permissions: { all: CHAT_PERMISSION_ID },
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
export class Chat {
|
|
93
|
-
public readonly messages: Table<Message>;
|
|
94
|
-
public readonly authors: Table<Author>;
|
|
95
|
-
public readonly channels: Table<Channel>;
|
|
96
|
-
public readonly providers: Table<Provider>;
|
|
97
|
-
public readonly rooms: Table<Room>;
|
|
98
|
-
public readonly votes: Table<Vote>;
|
|
99
|
-
public readonly reactionSignal: Signal<Reaction>;
|
|
100
|
-
private readonly eventRegistry: EventRegistry;
|
|
101
|
-
|
|
102
|
-
private constructor(private readonly omu: Omu) {
|
|
103
|
-
omu.sessions.require(PLUGIN_ID);
|
|
104
|
-
omu.permissions.require(CHAT_PERMISSION_ID);
|
|
105
|
-
this.eventRegistry = new EventRegistry(this);
|
|
106
|
-
this.messages = omu.tables.get(MESSAGE_TABLE_TYPE);
|
|
107
|
-
this.authors = omu.tables.get(AUTHOR_TABLE_TYPE);
|
|
108
|
-
this.channels = omu.tables.get(CHANNEL_TABLE_TYPE);
|
|
109
|
-
this.providers = omu.tables.get(PROVIDER_TABLE_TYPE);
|
|
110
|
-
this.rooms = omu.tables.get(ROOM_TABLE_TYPE);
|
|
111
|
-
this.votes = omu.tables.get(VOTE_TABLE_TYPE);
|
|
112
|
-
this.reactionSignal = omu.signals.get(REACTION_SIGNAL);
|
|
113
|
-
this.messages.setCacheSize(1000);
|
|
114
|
-
this.authors.setCacheSize(500);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
public static create(omu: Omu): Chat {
|
|
118
|
-
if (omu.ready) {
|
|
119
|
-
throw new Error('OMU instance is already started');
|
|
120
|
-
}
|
|
121
|
-
return new Chat(omu);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
public async createChannelTree(url: string): Promise<Channel[]> {
|
|
125
|
-
return await this.omu.endpoints.call(CREATE_CHANNEL_TREE_ENDPOINT, url);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
public on<P extends Array<any>>(event: EventSource<P>, handler: EventHandler<P>): void {
|
|
129
|
-
this.eventRegistry.register(event, handler);
|
|
130
|
-
}
|
|
131
|
-
}
|
package/src/const.ts
DELETED
package/src/event/event-types.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Author } from '../models/author.js';
|
|
2
|
-
import { Channel } from '../models/channel.js';
|
|
3
|
-
import { Message } from '../models/message.js';
|
|
4
|
-
import { Provider } from '../models/provider.js';
|
|
5
|
-
import { Room } from '../models/room.js';
|
|
6
|
-
import { Vote } from '../models/vote.js';
|
|
7
|
-
import { TableEvent } from './event.js';
|
|
8
|
-
|
|
9
|
-
export const events: { Message: TableEvent<Message>; Author: TableEvent<Author>; Channel: TableEvent<Channel>; Provider: TableEvent<Provider>; Room: TableEvent<Room>; Vote: TableEvent<Vote> } = {
|
|
10
|
-
Message: new TableEvent((chat) => chat.messages),
|
|
11
|
-
Author: new TableEvent((chat) => chat.authors),
|
|
12
|
-
Channel: new TableEvent((chat) => chat.channels),
|
|
13
|
-
Provider: new TableEvent((chat) => chat.providers),
|
|
14
|
-
Room: new TableEvent((chat) => chat.rooms),
|
|
15
|
-
Vote: new TableEvent((chat) => chat.votes),
|
|
16
|
-
};
|
package/src/event/event.ts
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import type { Table } from '@omujs/omu/api/table';
|
|
2
|
-
import type { Unlisten } from '@omujs/omu/event';
|
|
3
|
-
import { EventEmitter } from '@omujs/omu/event';
|
|
4
|
-
|
|
5
|
-
import type { Chat } from '../chat.js';
|
|
6
|
-
|
|
7
|
-
export type EventHandler<P extends Array<any>> = (...args: P) => Promise<void> | void;
|
|
8
|
-
|
|
9
|
-
export interface EventSource<P extends Array<any>> {
|
|
10
|
-
subscribe(handler: EventHandler<P>, chat: Chat): Unlisten;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export class ListenerEvent<P extends Array<any>> implements EventSource<P> {
|
|
14
|
-
constructor(private readonly getListener: (chat: Chat) => EventEmitter<P>) {}
|
|
15
|
-
|
|
16
|
-
public subscribe(handler: EventHandler<P>, chat: Chat): Unlisten {
|
|
17
|
-
const listener = this.getListener(chat);
|
|
18
|
-
return listener.listen(handler);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export class TableEvent<T> extends ListenerEvent<[Map<string, T>]> {
|
|
23
|
-
public readonly AddBatch: ListenerEvent<[Map<string, T>]>;
|
|
24
|
-
public readonly UpdateBatch: ListenerEvent<[Map<string, T>]>;
|
|
25
|
-
public readonly RemoveBatch: ListenerEvent<[Map<string, T>]>;
|
|
26
|
-
public readonly Add: EventSource<[T]>;
|
|
27
|
-
public readonly Update: EventSource<[T]>;
|
|
28
|
-
public readonly Remove: EventSource<[T]>;
|
|
29
|
-
public readonly Clear: EventSource<[]>;
|
|
30
|
-
public readonly wrappers: Record<string, Unlisten>;
|
|
31
|
-
|
|
32
|
-
constructor(private readonly getTable: (chat: Chat) => Table<T>) {
|
|
33
|
-
super((chat) => getTable(chat).event.cacheUpdate);
|
|
34
|
-
this.AddBatch = new ListenerEvent((chat) => getTable(chat).event.add);
|
|
35
|
-
this.UpdateBatch = new ListenerEvent((chat) => getTable(chat).event.update);
|
|
36
|
-
this.RemoveBatch = new ListenerEvent((chat) => getTable(chat).event.remove);
|
|
37
|
-
this.Add = this.createBatchSubscriber((table) => table.event.add);
|
|
38
|
-
this.Update = this.createBatchSubscriber((table) => table.event.update);
|
|
39
|
-
this.Remove = this.createBatchSubscriber((table) => table.event.remove);
|
|
40
|
-
this.Clear = new ListenerEvent((client) => getTable(client).event.clear);
|
|
41
|
-
this.wrappers = {};
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
private static createBatchWrapper<T>(emit: EventHandler<[T]>): EventHandler<[Map<string, T>]> {
|
|
45
|
-
return async (items) => {
|
|
46
|
-
for (const item of items.values()) {
|
|
47
|
-
await emit(item);
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
private createBatchSubscriber(
|
|
53
|
-
getListener: (table: Table<T>) => EventEmitter<[Map<string, T>]>,
|
|
54
|
-
): EventSource<[T]> {
|
|
55
|
-
let batchWrapper: EventHandler<[Map<string, T>]> | null = null;
|
|
56
|
-
|
|
57
|
-
const subscribe = (emit: EventHandler<[T]>, chat: Chat): Unlisten => {
|
|
58
|
-
const table = this.getTable(chat);
|
|
59
|
-
const listener = getListener(table);
|
|
60
|
-
batchWrapper = TableEvent.createBatchWrapper((item) => emit(item));
|
|
61
|
-
const stopListen = table.listen();
|
|
62
|
-
const clearEvent = listener.listen(batchWrapper);
|
|
63
|
-
return () => {
|
|
64
|
-
stopListen();
|
|
65
|
-
clearEvent();
|
|
66
|
-
};
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
return {
|
|
70
|
-
subscribe,
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
type Entry<P extends Array<any>> = {
|
|
76
|
-
source: EventSource<P>;
|
|
77
|
-
listeners: EventEmitter<P>;
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
export class EventRegistry {
|
|
81
|
-
private readonly chat: Chat;
|
|
82
|
-
private readonly events: Map<EventSource<any>, Entry<any>>;
|
|
83
|
-
|
|
84
|
-
constructor(chat: Chat) {
|
|
85
|
-
this.chat = chat;
|
|
86
|
-
this.events = new Map();
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
public register<P extends Array<any>>(event: EventSource<P>, handler: EventHandler<P>): void {
|
|
90
|
-
let entry = this.events.get(event) as Entry<P> | null;
|
|
91
|
-
if (!entry) {
|
|
92
|
-
const newEntry: Entry<P> = {
|
|
93
|
-
source: event,
|
|
94
|
-
listeners: new EventEmitter(),
|
|
95
|
-
};
|
|
96
|
-
entry = newEntry;
|
|
97
|
-
this.events.set(event, newEntry);
|
|
98
|
-
event.subscribe((...args) => newEntry.listeners.emit(...args), this.chat);
|
|
99
|
-
}
|
|
100
|
-
entry.listeners.listen((...args) => handler(...args));
|
|
101
|
-
}
|
|
102
|
-
}
|
package/src/models/author.ts
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { Identifier } from '@omujs/omu';
|
|
2
|
-
|
|
3
|
-
import type { RoleJson } from './role.js';
|
|
4
|
-
import { Role } from './role.js';
|
|
5
|
-
|
|
6
|
-
export type AuthorMetadata = {
|
|
7
|
-
url?: string;
|
|
8
|
-
screen_id?: string;
|
|
9
|
-
avatar_url?: string;
|
|
10
|
-
description?: string;
|
|
11
|
-
links?: string[];
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export type AuthorJson = {
|
|
15
|
-
provider_id: string;
|
|
16
|
-
id: string;
|
|
17
|
-
metadata: AuthorMetadata;
|
|
18
|
-
name?: string;
|
|
19
|
-
avatar_url?: string;
|
|
20
|
-
roles?: RoleJson[];
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export class Author {
|
|
24
|
-
public providerId: Identifier;
|
|
25
|
-
public id: Identifier;
|
|
26
|
-
public metadata: AuthorMetadata;
|
|
27
|
-
public name?: string;
|
|
28
|
-
public avatarUrl?: string;
|
|
29
|
-
public roles?: Role[];
|
|
30
|
-
|
|
31
|
-
constructor(options: {
|
|
32
|
-
providerId: Identifier;
|
|
33
|
-
id: Identifier;
|
|
34
|
-
metadata?: AuthorMetadata;
|
|
35
|
-
name?: string;
|
|
36
|
-
avatarUrl?: string;
|
|
37
|
-
roles?: Role[];
|
|
38
|
-
}) {
|
|
39
|
-
this.providerId = options.providerId;
|
|
40
|
-
this.id = options.id;
|
|
41
|
-
this.metadata = options.metadata || {};
|
|
42
|
-
this.name = options.name;
|
|
43
|
-
this.avatarUrl = options.avatarUrl;
|
|
44
|
-
this.roles = options.roles;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
public static deserialize(info: AuthorJson): Author {
|
|
48
|
-
return new Author({
|
|
49
|
-
providerId: Identifier.fromKey(info.provider_id),
|
|
50
|
-
id: Identifier.fromKey(info.id),
|
|
51
|
-
name: info.name,
|
|
52
|
-
avatarUrl: info.avatar_url,
|
|
53
|
-
roles: info.roles?.map((role) => Role.fromJson(role)),
|
|
54
|
-
metadata: info.metadata,
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
key(): string {
|
|
59
|
-
return this.id.key();
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
public static serialize(item: Author): AuthorJson {
|
|
63
|
-
return {
|
|
64
|
-
provider_id: item.providerId.key(),
|
|
65
|
-
id: item.id.key(),
|
|
66
|
-
name: item.name,
|
|
67
|
-
avatar_url: item.avatarUrl,
|
|
68
|
-
roles: item.roles?.map((role) => role.toJson()),
|
|
69
|
-
metadata: item.metadata,
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
}
|
package/src/models/channel.ts
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { Identifier } from '@omujs/omu';
|
|
2
|
-
|
|
3
|
-
export type ChannelJson = {
|
|
4
|
-
provider_id: string;
|
|
5
|
-
id: string;
|
|
6
|
-
url: string;
|
|
7
|
-
name: string;
|
|
8
|
-
description: string;
|
|
9
|
-
active: boolean;
|
|
10
|
-
icon_url: string;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export class Channel {
|
|
14
|
-
providerId: Identifier;
|
|
15
|
-
id: Identifier;
|
|
16
|
-
url: string;
|
|
17
|
-
name: string;
|
|
18
|
-
description: string;
|
|
19
|
-
active: boolean;
|
|
20
|
-
iconUrl: string;
|
|
21
|
-
|
|
22
|
-
constructor(option: {
|
|
23
|
-
providerId: Identifier;
|
|
24
|
-
id: Identifier;
|
|
25
|
-
url: string;
|
|
26
|
-
name: string;
|
|
27
|
-
description: string;
|
|
28
|
-
active: boolean;
|
|
29
|
-
iconUrl: string;
|
|
30
|
-
}) {
|
|
31
|
-
this.providerId = option.providerId;
|
|
32
|
-
this.id = option.id;
|
|
33
|
-
this.url = option.url;
|
|
34
|
-
this.name = option.name;
|
|
35
|
-
this.description = option.description;
|
|
36
|
-
this.active = option.active;
|
|
37
|
-
this.iconUrl = option.iconUrl;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
public static deserialize(json: ChannelJson): Channel {
|
|
41
|
-
return new Channel({
|
|
42
|
-
providerId: Identifier.fromKey(json.provider_id),
|
|
43
|
-
id: Identifier.fromKey(json.id),
|
|
44
|
-
url: json.url,
|
|
45
|
-
name: json.name,
|
|
46
|
-
description: json.description,
|
|
47
|
-
active: json.active,
|
|
48
|
-
iconUrl: json.icon_url,
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
key(): string {
|
|
53
|
-
return this.id.key();
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
public static serialize(item: Channel): ChannelJson {
|
|
57
|
-
return {
|
|
58
|
-
provider_id: item.providerId.key(),
|
|
59
|
-
id: item.id.key(),
|
|
60
|
-
url: item.url,
|
|
61
|
-
name: item.name,
|
|
62
|
-
description: item.description,
|
|
63
|
-
active: item.active,
|
|
64
|
-
icon_url: item.iconUrl,
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
}
|
package/src/models/content.ts
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { JsonType } from '@omujs/omu/serialize';
|
|
2
|
-
|
|
3
|
-
export type ComponentType<T extends string, D extends JsonType = JsonType> = {
|
|
4
|
-
type: T;
|
|
5
|
-
data: D;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export type Root = ComponentType<'root', Component[]>;
|
|
9
|
-
|
|
10
|
-
export type Text = ComponentType<'text', string>;
|
|
11
|
-
|
|
12
|
-
export type Image = ComponentType<'image', {
|
|
13
|
-
url: string;
|
|
14
|
-
id: string;
|
|
15
|
-
name?: string;
|
|
16
|
-
}>;
|
|
17
|
-
|
|
18
|
-
export type Asset = ComponentType<'asset', {
|
|
19
|
-
id: string;
|
|
20
|
-
}>;
|
|
21
|
-
|
|
22
|
-
export type Link = ComponentType<'link', {
|
|
23
|
-
url: string;
|
|
24
|
-
children: Component[];
|
|
25
|
-
}>;
|
|
26
|
-
|
|
27
|
-
export type System = ComponentType<'system', Component[]>;
|
|
28
|
-
|
|
29
|
-
export type Component =
|
|
30
|
-
| Root
|
|
31
|
-
| Text
|
|
32
|
-
| Image
|
|
33
|
-
| Asset
|
|
34
|
-
| Link
|
|
35
|
-
| System;
|
|
36
|
-
|
|
37
|
-
export function children(component: Component): Component[] {
|
|
38
|
-
switch (component.type) {
|
|
39
|
-
case 'root': return component.data;
|
|
40
|
-
case 'system': return component.data;
|
|
41
|
-
case 'link': return component.data.children;
|
|
42
|
-
case 'text': return [];
|
|
43
|
-
case 'image': return [];
|
|
44
|
-
case 'asset': return [];
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export function *walk(component: Component): Iterable<Component> {
|
|
49
|
-
const queue = [component];
|
|
50
|
-
while (queue.length > 0) {
|
|
51
|
-
const component = queue.pop();
|
|
52
|
-
if (!component) return;
|
|
53
|
-
yield component;
|
|
54
|
-
queue.push(...children(component).slice().reverse());
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export function format(component: Component): string {
|
|
59
|
-
return [...walk(component)]
|
|
60
|
-
.filter(it => it.type === 'text')
|
|
61
|
-
.map(it => it.data).join('');
|
|
62
|
-
}
|
package/src/models/gift.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
export type GiftJson = {
|
|
2
|
-
id: string;
|
|
3
|
-
name?: string;
|
|
4
|
-
amount?: number;
|
|
5
|
-
is_paid?: boolean;
|
|
6
|
-
image_url?: string;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export class Gift {
|
|
10
|
-
id: string;
|
|
11
|
-
name?: string;
|
|
12
|
-
amount?: number;
|
|
13
|
-
isPaid?: boolean;
|
|
14
|
-
imageUrl?: string;
|
|
15
|
-
|
|
16
|
-
constructor(options: {
|
|
17
|
-
id: string;
|
|
18
|
-
name?: string;
|
|
19
|
-
amount?: number;
|
|
20
|
-
isPaid?: boolean;
|
|
21
|
-
imageUrl?: string;
|
|
22
|
-
}) {
|
|
23
|
-
this.id = options.id;
|
|
24
|
-
this.name = options.name;
|
|
25
|
-
this.amount = options.amount;
|
|
26
|
-
this.isPaid = options.isPaid;
|
|
27
|
-
this.imageUrl = options.imageUrl;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
static fromJson(options: GiftJson): Gift {
|
|
31
|
-
return new Gift({
|
|
32
|
-
id: options.id,
|
|
33
|
-
name: options.name,
|
|
34
|
-
amount: options.amount,
|
|
35
|
-
isPaid: options.is_paid,
|
|
36
|
-
imageUrl: options.image_url,
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
toJson(): GiftJson {
|
|
41
|
-
return {
|
|
42
|
-
id: this.id,
|
|
43
|
-
name: this.name,
|
|
44
|
-
amount: this.amount,
|
|
45
|
-
is_paid: this.isPaid,
|
|
46
|
-
image_url: this.imageUrl,
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
}
|
package/src/models/message.ts
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { Identifier } from '@omujs/omu';
|
|
2
|
-
import * as content from './content.js';
|
|
3
|
-
import type { GiftJson } from './gift.js';
|
|
4
|
-
import { Gift } from './gift.js';
|
|
5
|
-
import type { PaidJson } from './paid.js';
|
|
6
|
-
import { Paid } from './paid.js';
|
|
7
|
-
|
|
8
|
-
export type MessageJson = {
|
|
9
|
-
room_id: string;
|
|
10
|
-
id: string;
|
|
11
|
-
created_at: string; // ISO 8601 date string
|
|
12
|
-
author_id?: string;
|
|
13
|
-
content?: content.Component;
|
|
14
|
-
paid?: PaidJson;
|
|
15
|
-
gifts?: GiftJson[];
|
|
16
|
-
deleted?: boolean;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export class Message {
|
|
20
|
-
public roomId: Identifier;
|
|
21
|
-
public id: Identifier;
|
|
22
|
-
public authorId?: Identifier;
|
|
23
|
-
public content?: content.Component;
|
|
24
|
-
public paid?: Paid;
|
|
25
|
-
public gifts?: Gift[];
|
|
26
|
-
public createdAt: Date;
|
|
27
|
-
public deleted?: boolean;
|
|
28
|
-
|
|
29
|
-
constructor(options: {
|
|
30
|
-
roomId: Identifier;
|
|
31
|
-
id: Identifier;
|
|
32
|
-
authorId?: Identifier;
|
|
33
|
-
createdAt: Date;
|
|
34
|
-
content?: content.Component;
|
|
35
|
-
paid?: Paid;
|
|
36
|
-
gifts?: Gift[];
|
|
37
|
-
deleted?: boolean;
|
|
38
|
-
}) {
|
|
39
|
-
if (!(options.createdAt instanceof Date)) {
|
|
40
|
-
throw new Error('created_at must be a Date');
|
|
41
|
-
}
|
|
42
|
-
this.roomId = options.roomId;
|
|
43
|
-
this.id = options.id;
|
|
44
|
-
this.authorId = options.authorId;
|
|
45
|
-
this.content = options.content;
|
|
46
|
-
this.paid = options.paid;
|
|
47
|
-
this.gifts = options.gifts;
|
|
48
|
-
this.createdAt = options.createdAt;
|
|
49
|
-
this.deleted = options.deleted;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
public static serialize(data: Message): MessageJson {
|
|
53
|
-
return {
|
|
54
|
-
room_id: data.roomId.key(),
|
|
55
|
-
id: data.id.key(),
|
|
56
|
-
author_id: data.authorId?.key(),
|
|
57
|
-
created_at: data.createdAt.toISOString(),
|
|
58
|
-
content: data.content,
|
|
59
|
-
paid: data.paid?.toJson(),
|
|
60
|
-
gifts: data.gifts?.map((gift) => gift.toJson()),
|
|
61
|
-
deleted: data.deleted,
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
public static deserialize(info: MessageJson): Message {
|
|
66
|
-
return new Message({
|
|
67
|
-
roomId: Identifier.fromKey(info.room_id),
|
|
68
|
-
id: Identifier.fromKey(info.id),
|
|
69
|
-
authorId: info.author_id ? Identifier.fromKey(info.author_id) : undefined,
|
|
70
|
-
content: info.content,
|
|
71
|
-
paid: info.paid && Paid.fromJson(info.paid),
|
|
72
|
-
gifts: info.gifts?.map((gift) => Gift.fromJson(gift)),
|
|
73
|
-
createdAt: new Date(info.created_at),
|
|
74
|
-
deleted: info.deleted,
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
get text(): string {
|
|
79
|
-
if (!this.content) {
|
|
80
|
-
return '';
|
|
81
|
-
}
|
|
82
|
-
return content.format(this.content);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
key(): string {
|
|
86
|
-
return this.id.key();
|
|
87
|
-
}
|
|
88
|
-
}
|
package/src/models/paid.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export type PaidJson = {
|
|
2
|
-
amount: number;
|
|
3
|
-
currency: string;
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
export class Paid {
|
|
7
|
-
constructor(
|
|
8
|
-
public amount: number,
|
|
9
|
-
public currency: string,
|
|
10
|
-
) { }
|
|
11
|
-
|
|
12
|
-
static fromJson(options: PaidJson): Paid {
|
|
13
|
-
return new Paid(options.amount, options.currency);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
toJson(): PaidJson {
|
|
17
|
-
return {
|
|
18
|
-
amount: this.amount,
|
|
19
|
-
currency: this.currency,
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
}
|
package/src/models/provider.ts
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { Identifier } from '@omujs/omu';
|
|
2
|
-
|
|
3
|
-
export type ProviderJson = {
|
|
4
|
-
id: string;
|
|
5
|
-
url: string;
|
|
6
|
-
name: string;
|
|
7
|
-
version: string;
|
|
8
|
-
repository_url: string;
|
|
9
|
-
image_url?: string;
|
|
10
|
-
description: string;
|
|
11
|
-
regex: string;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export class Provider {
|
|
15
|
-
public id: Identifier;
|
|
16
|
-
public url: string;
|
|
17
|
-
public name: string;
|
|
18
|
-
public version: string;
|
|
19
|
-
public repositoryUrl: string;
|
|
20
|
-
public imageUrl?: string;
|
|
21
|
-
public description: string;
|
|
22
|
-
public regex: string;
|
|
23
|
-
|
|
24
|
-
constructor(options: {
|
|
25
|
-
id: Identifier;
|
|
26
|
-
url: string;
|
|
27
|
-
name: string;
|
|
28
|
-
version: string;
|
|
29
|
-
repository_url: string;
|
|
30
|
-
image_url?: string;
|
|
31
|
-
description: string;
|
|
32
|
-
regex: string;
|
|
33
|
-
}) {
|
|
34
|
-
this.id = options.id;
|
|
35
|
-
this.url = options.url;
|
|
36
|
-
this.name = options.name;
|
|
37
|
-
this.version = options.version;
|
|
38
|
-
this.repositoryUrl = options.repository_url;
|
|
39
|
-
this.imageUrl = options.image_url;
|
|
40
|
-
this.description = options.description;
|
|
41
|
-
this.regex = options.regex;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
public static serialize(item: Provider): ProviderJson {
|
|
45
|
-
return {
|
|
46
|
-
id: item.id.key(),
|
|
47
|
-
url: item.url,
|
|
48
|
-
name: item.name,
|
|
49
|
-
version: item.version,
|
|
50
|
-
repository_url: item.repositoryUrl,
|
|
51
|
-
image_url: item.imageUrl,
|
|
52
|
-
description: item.description,
|
|
53
|
-
regex: item.regex,
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
public static deserialize(data: ProviderJson): Provider {
|
|
58
|
-
return new Provider({
|
|
59
|
-
id: Identifier.fromKey(data.id),
|
|
60
|
-
url: data.url,
|
|
61
|
-
name: data.name,
|
|
62
|
-
version: data.version,
|
|
63
|
-
repository_url: data.repository_url,
|
|
64
|
-
image_url: data.image_url,
|
|
65
|
-
description: data.description,
|
|
66
|
-
regex: data.regex,
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
key(): string {
|
|
71
|
-
return this.id.key();
|
|
72
|
-
}
|
|
73
|
-
}
|