@omujs/chat 0.9.10 → 0.9.26

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 (102) hide show
  1. package/CHANGELOG.md +146 -0
  2. package/README.md +19 -1
  3. package/dist/dts/chat.d.ts +18 -19
  4. package/dist/dts/const.d.ts +2 -3
  5. package/dist/dts/event/event-types.d.ts +13 -8
  6. package/dist/dts/event/event.d.ts +24 -25
  7. package/dist/dts/event/index.d.ts +2 -3
  8. package/dist/dts/index.d.ts +6 -5
  9. package/dist/dts/models/author.d.ts +32 -35
  10. package/dist/dts/models/channel.d.ts +28 -31
  11. package/dist/dts/models/content.d.ts +26 -84
  12. package/dist/dts/models/gift.d.ts +20 -22
  13. package/dist/dts/models/index.d.ts +13 -12
  14. package/dist/dts/models/message.d.ts +37 -40
  15. package/dist/dts/models/paid.d.ts +8 -10
  16. package/dist/dts/models/provider.d.ts +31 -34
  17. package/dist/dts/models/reaction.d.ts +18 -20
  18. package/dist/dts/models/role.d.ts +23 -25
  19. package/dist/dts/models/room.d.ts +39 -42
  20. package/dist/dts/models/vote.d.ts +28 -31
  21. package/dist/dts/permissions.d.ts +7 -7
  22. package/dist/esm/chat.js +7652 -112
  23. package/dist/esm/const.js +4751 -3
  24. package/dist/esm/event/event-types.js +75 -9
  25. package/dist/esm/event/event.js +101 -75
  26. package/dist/esm/event/index.js +115 -3
  27. package/dist/esm/index.js +7698 -5
  28. package/dist/esm/models/author.js +4823 -38
  29. package/dist/esm/models/channel.js +4789 -41
  30. package/dist/esm/models/content.js +39 -168
  31. package/dist/esm/models/gift.js +39 -32
  32. package/dist/esm/models/index.js +5190 -12
  33. package/dist/esm/models/message.js +4886 -57
  34. package/dist/esm/models/paid.js +24 -17
  35. package/dist/esm/models/provider.js +4792 -44
  36. package/dist/esm/models/reaction.js +4763 -15
  37. package/dist/esm/models/role.js +43 -36
  38. package/dist/esm/models/room.js +4788 -40
  39. package/dist/esm/models/vote.js +4784 -36
  40. package/dist/esm/permissions.js +4764 -8
  41. package/package.json +26 -37
  42. package/src/chat.ts +49 -43
  43. package/src/const.ts +2 -2
  44. package/src/event/event-types.ts +13 -7
  45. package/src/event/event.ts +18 -18
  46. package/src/event/index.ts +2 -1
  47. package/src/index.ts +5 -4
  48. package/src/models/author.ts +15 -17
  49. package/src/models/channel.ts +11 -13
  50. package/src/models/content.ts +42 -206
  51. package/src/models/gift.ts +1 -3
  52. package/src/models/index.ts +14 -11
  53. package/src/models/message.ts +19 -22
  54. package/src/models/paid.ts +1 -3
  55. package/src/models/provider.ts +16 -18
  56. package/src/models/reaction.ts +5 -6
  57. package/src/models/role.ts +1 -3
  58. package/src/models/room.ts +11 -13
  59. package/src/models/vote.ts +9 -11
  60. package/src/permissions.ts +8 -7
  61. package/tsconfig.json +5 -2
  62. package/tsconfig.tsbuildinfo +1 -0
  63. package/LICENSE +0 -21
  64. package/dist/dts/chat.d.ts.map +0 -1
  65. package/dist/dts/const.d.ts.map +0 -1
  66. package/dist/dts/event/event-types.d.ts.map +0 -1
  67. package/dist/dts/event/event.d.ts.map +0 -1
  68. package/dist/dts/event/index.d.ts.map +0 -1
  69. package/dist/dts/index.d.ts.map +0 -1
  70. package/dist/dts/models/author.d.ts.map +0 -1
  71. package/dist/dts/models/channel.d.ts.map +0 -1
  72. package/dist/dts/models/content.d.ts.map +0 -1
  73. package/dist/dts/models/gift.d.ts.map +0 -1
  74. package/dist/dts/models/index.d.ts.map +0 -1
  75. package/dist/dts/models/message.d.ts.map +0 -1
  76. package/dist/dts/models/paid.d.ts.map +0 -1
  77. package/dist/dts/models/provider.d.ts.map +0 -1
  78. package/dist/dts/models/reaction.d.ts.map +0 -1
  79. package/dist/dts/models/role.d.ts.map +0 -1
  80. package/dist/dts/models/room.d.ts.map +0 -1
  81. package/dist/dts/models/vote.d.ts.map +0 -1
  82. package/dist/dts/permissions.d.ts.map +0 -1
  83. package/dist/esm/chat.js.map +0 -1
  84. package/dist/esm/const.js.map +0 -1
  85. package/dist/esm/event/event-types.js.map +0 -1
  86. package/dist/esm/event/event.js.map +0 -1
  87. package/dist/esm/event/index.js.map +0 -1
  88. package/dist/esm/index.js.map +0 -1
  89. package/dist/esm/models/author.js.map +0 -1
  90. package/dist/esm/models/channel.js.map +0 -1
  91. package/dist/esm/models/content.js.map +0 -1
  92. package/dist/esm/models/gift.js.map +0 -1
  93. package/dist/esm/models/index.js.map +0 -1
  94. package/dist/esm/models/message.js.map +0 -1
  95. package/dist/esm/models/paid.js.map +0 -1
  96. package/dist/esm/models/provider.js.map +0 -1
  97. package/dist/esm/models/reaction.js.map +0 -1
  98. package/dist/esm/models/role.js.map +0 -1
  99. package/dist/esm/models/room.js.map +0 -1
  100. package/dist/esm/models/vote.js.map +0 -1
  101. package/dist/esm/permissions.js.map +0 -1
  102. package/eslint.config.js +0 -6
@@ -1,226 +1,62 @@
1
- import { Identifier } from '@omujs/omu';
1
+ import { JsonType } from '@omujs/omu/serialize';
2
2
 
3
- type Primitive =
4
- | {
5
- [key: string]: Primitive | string | number | boolean | null;
6
- }
7
- | any[]
8
- | string
9
- | number
10
- | boolean
11
- | null;
12
-
13
- export type ComponentJson = {
14
- type: string;
15
- data: Primitive;
16
- };
17
-
18
- export interface Parent {
19
- children: Component[];
20
- }
21
-
22
- export abstract class Component<T extends string = string, D extends Primitive = Primitive> {
23
- constructor(public type: T) {}
24
-
25
- abstract toJson(): D;
26
-
27
- isParent(): this is Parent {
28
- return 'children' in this;
29
- }
30
-
31
- walk(cb: (component: Component) => void): void {
32
- const stack: Component[] = [this];
33
- while (stack.length) {
34
- const component = stack.pop();
35
- if (!component) {
36
- continue;
37
- }
38
- cb(component);
39
- if (component.isParent()) {
40
- stack.push(...component.children);
41
- }
42
- }
43
- }
44
-
45
- *iter(): Iterable<Component> {
46
- const stack: Component[] = [this];
47
- while (stack.length) {
48
- const component = stack.pop();
49
- if (!component) {
50
- continue;
51
- }
52
- yield component;
53
- if (component.isParent()) {
54
- stack.push(...component.children);
55
- }
56
- }
57
- }
58
-
59
- toString(): string {
60
- const parts = [] as string[];
61
- for (const component of this.iter()) {
62
- if (component instanceof Text) {
63
- parts.push(component.text);
64
- }
65
- }
66
- return parts.join('');
67
- }
68
- }
69
-
70
- export type ComponentType<D, C extends Component> = {
71
- type: string;
72
- fromJson(json: D): C;
3
+ export type ComponentType<T extends string, D extends JsonType = JsonType> = {
4
+ type: T;
5
+ data: D;
73
6
  };
74
7
 
75
- const componentTypes: Record<string, ComponentType<unknown, Component> | undefined> = {};
76
-
77
- export function deserialize(json: ComponentJson): Component {
78
- const type = componentTypes[json.type];
79
- if (!type) {
80
- throw new Error(`Unknown component type: ${json.type}`);
81
- }
82
- return type.fromJson(json.data);
83
- }
84
-
85
- export function serialize(component: Component): ComponentJson {
86
- return {
87
- type: component.type,
88
- data: component.toJson(),
89
- };
90
- }
91
-
92
- export function register<D, C extends Component>(type: string, deserialize: (json: D) => C): void {
93
- if (componentTypes[type]) {
94
- throw new Error(`Component type already registered: ${type}`);
95
- }
96
- componentTypes[type] = {
97
- type,
98
- fromJson: deserialize,
99
- };
100
- }
101
-
102
- export type RootData = ComponentJson[];
103
-
104
- export class Root extends Component<'root', RootData> implements Parent {
105
- constructor(public children: Component[]) {
106
- super('root');
107
- }
108
-
109
- toJson(): RootData {
110
- return this.children.map(serialize);
111
- }
112
-
113
- add(component: Component): void {
114
- this.children.push(component);
115
- }
116
-
117
- text(): string {
118
- const parts = [] as string[];
119
- for (const component of this.iter()) {
120
- if (component instanceof Text) {
121
- parts.push(component.text);
122
- }
123
- }
124
- return parts.join('');
125
- }
126
- }
127
-
128
- export type TextData = string;
129
-
130
- export class Text extends Component<'text', TextData> {
131
- constructor(public text: string) {
132
- super('text');
133
- }
134
-
135
- toJson(): TextData {
136
- return this.text;
137
- }
8
+ export type Root = ComponentType<'root', Component[]>;
138
9
 
139
- static of(text: string): Text {
140
- return new Text(text);
141
- }
142
- }
10
+ export type Text = ComponentType<'text', string>;
143
11
 
144
- export type ImageData = {
12
+ export type Image = ComponentType<'image', {
145
13
  url: string;
146
14
  id: string;
147
15
  name?: string;
148
- };
149
-
150
- export class Image extends Component<'image', ImageData> {
151
- constructor(
152
- public url: string,
153
- public id: string,
154
- public name: string | undefined = undefined,
155
- ) {
156
- super('image');
157
- }
158
-
159
- toJson(): ImageData {
160
- return {
161
- url: this.url,
162
- id: this.id,
163
- name: this.name,
164
- };
165
- }
166
-
167
- static of({ url, id, name }: { url: string; id: string; name?: string }): Image {
168
- return new Image(url, id, name);
169
- }
170
- }
16
+ }>;
171
17
 
172
- export type AssetData = {
18
+ export type Asset = ComponentType<'asset', {
173
19
  id: string;
174
- };
175
-
176
- export class Asset extends Component<'asset', AssetData> {
177
- constructor(public id: Identifier) {
178
- super('asset');
179
- }
180
-
181
- toJson(): AssetData {
182
- return {
183
- id: this.id.key(),
184
- };
185
- }
186
- }
20
+ }>;
187
21
 
188
- export type LinkData = {
22
+ export type Link = ComponentType<'link', {
189
23
  url: string;
190
- children: ComponentJson[];
191
- };
192
-
193
- export class Link extends Component<'link', LinkData> implements Parent {
194
- constructor(
195
- public url: string,
196
- public children: Component[],
197
- ) {
198
- super('link');
199
- }
24
+ children: Component[];
25
+ }>;
200
26
 
201
- toJson(): LinkData {
202
- return {
203
- url: this.url,
204
- children: this.children.map(serialize),
205
- };
206
- }
207
- }
27
+ export type System = ComponentType<'system', Component[]>;
208
28
 
209
- export type SystemData = ComponentJson[];
29
+ export type Component =
30
+ | Root
31
+ | Text
32
+ | Image
33
+ | Asset
34
+ | Link
35
+ | System;
210
36
 
211
- export class System extends Component<'system', SystemData> implements Parent {
212
- constructor(public children: Component[]) {
213
- super('system');
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 [];
214
45
  }
46
+ }
215
47
 
216
- toJson(): SystemData {
217
- return this.children.map(serialize);
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());
218
55
  }
219
56
  }
220
57
 
221
- register('root', (data: RootData) => new Root(data.map(deserialize)));
222
- register('text', (data: TextData) => new Text(data));
223
- register('image', (data: ImageData) => new Image(data.url, data.id, data.name));
224
- register('asset', (data: AssetData) => new Asset(Identifier.fromKey(data.id)));
225
- register('link', (data: LinkData) => new Link(data.url, data.children.map(deserialize)));
226
- register('system', (data: SystemData) => new System(data.map(deserialize)));
58
+ export function format(component: Component): string {
59
+ return [...walk(component)]
60
+ .filter(it => it.type === 'text')
61
+ .map(it => it.data).join('');
62
+ }
@@ -1,5 +1,3 @@
1
- import type { Model } from '@omujs/omu/model.js';
2
-
3
1
  export type GiftJson = {
4
2
  id: string;
5
3
  name?: string;
@@ -8,7 +6,7 @@ export type GiftJson = {
8
6
  image_url?: string;
9
7
  };
10
8
 
11
- export class Gift implements Model<GiftJson> {
9
+ export class Gift {
12
10
  id: string;
13
11
  name?: string;
14
12
  amount?: number;
@@ -1,11 +1,14 @@
1
- export { Author } from './author.js';
2
- export { Channel } from './channel.js';
3
- export * as content from './content.js';
4
- export { Gift } from './gift.js';
5
- export { Message } from './message.js';
6
- export { Paid } from './paid.js';
7
- export { Reaction } from './reaction.js';
8
- export { Provider } from './provider.js';
9
- export { Role } from './role.js';
10
- export { Room } from './room.js';
11
- export { Vote, Choice } from './vote.js';
1
+ export { Author, AuthorJson } from './author.js';
2
+ export { Channel, ChannelJson } from './channel.js';
3
+ export { Asset, Component, ComponentType, Image, Link, Root, System, Text } from './content.js';
4
+ export { Gift, GiftJson } from './gift.js';
5
+ export { Message, MessageJson } from './message.js';
6
+ export { Paid, PaidJson } from './paid.js';
7
+ export { Provider, ProviderJson } from './provider.js';
8
+ export { Reaction, ReactionJson } from './reaction.js';
9
+ export { Role, RoleJson } from './role.js';
10
+ export { Room, RoomJson } from './room.js';
11
+ export { Choice, Vote, VoteJson } from './vote.js';
12
+ export { Content };
13
+ import * as Content from './content.js';
14
+
@@ -1,7 +1,4 @@
1
- import { Identifier } from '@omujs/omu/identifier.js';
2
- import type { Keyable, Timestamped } from '@omujs/omu/interface.js';
3
- import type { Model } from '@omujs/omu/model.js';
4
-
1
+ import { Identifier } from '@omujs/omu';
5
2
  import * as content from './content.js';
6
3
  import type { GiftJson } from './gift.js';
7
4
  import { Gift } from './gift.js';
@@ -13,13 +10,13 @@ export type MessageJson = {
13
10
  id: string;
14
11
  created_at: string; // ISO 8601 date string
15
12
  author_id?: string;
16
- content?: content.ComponentJson;
13
+ content?: content.Component;
17
14
  paid?: PaidJson;
18
15
  gifts?: GiftJson[];
19
16
  deleted?: boolean;
20
17
  };
21
18
 
22
- export class Message implements Model<MessageJson>, Keyable, Timestamped {
19
+ export class Message {
23
20
  public roomId: Identifier;
24
21
  public id: Identifier;
25
22
  public authorId?: Identifier;
@@ -52,12 +49,25 @@ export class Message implements Model<MessageJson>, Keyable, Timestamped {
52
49
  this.deleted = options.deleted;
53
50
  }
54
51
 
55
- static fromJson(info: MessageJson): Message {
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 {
56
66
  return new Message({
57
67
  roomId: Identifier.fromKey(info.room_id),
58
68
  id: Identifier.fromKey(info.id),
59
69
  authorId: info.author_id ? Identifier.fromKey(info.author_id) : undefined,
60
- content: info.content && content.deserialize(info.content),
70
+ content: info.content,
61
71
  paid: info.paid && Paid.fromJson(info.paid),
62
72
  gifts: info.gifts?.map((gift) => Gift.fromJson(gift)),
63
73
  createdAt: new Date(info.created_at),
@@ -69,23 +79,10 @@ export class Message implements Model<MessageJson>, Keyable, Timestamped {
69
79
  if (!this.content) {
70
80
  return '';
71
81
  }
72
- return this.content.toString();
82
+ return content.format(this.content);
73
83
  }
74
84
 
75
85
  key(): string {
76
86
  return this.id.key();
77
87
  }
78
-
79
- toJson(): MessageJson {
80
- return {
81
- room_id: this.roomId.key(),
82
- id: this.id.key(),
83
- author_id: this.authorId?.key(),
84
- created_at: this.createdAt.toISOString(),
85
- content: this.content && content.serialize(this.content),
86
- paid: this.paid?.toJson(),
87
- gifts: this.gifts?.map((gift) => gift.toJson()),
88
- deleted: this.deleted,
89
- };
90
- }
91
88
  }
@@ -1,11 +1,9 @@
1
- import type { Model } from '@omujs/omu/model.js';
2
-
3
1
  export type PaidJson = {
4
2
  amount: number;
5
3
  currency: string;
6
4
  };
7
5
 
8
- export class Paid implements Model<PaidJson> {
6
+ export class Paid {
9
7
  constructor(
10
8
  public amount: number,
11
9
  public currency: string,
@@ -1,6 +1,4 @@
1
- import { Identifier } from '@omujs/omu/identifier.js';
2
- import type { Keyable } from '@omujs/omu/interface.js';
3
- import type { Model } from '@omujs/omu/model.js';
1
+ import { Identifier } from '@omujs/omu';
4
2
 
5
3
  export type ProviderJson = {
6
4
  id: string;
@@ -13,7 +11,7 @@ export type ProviderJson = {
13
11
  regex: string;
14
12
  };
15
13
 
16
- export class Provider implements Keyable, Model<ProviderJson> {
14
+ export class Provider {
17
15
  public id: Identifier;
18
16
  public url: string;
19
17
  public name: string;
@@ -43,7 +41,20 @@ export class Provider implements Keyable, Model<ProviderJson> {
43
41
  this.regex = options.regex;
44
42
  }
45
43
 
46
- static fromJson(data: ProviderJson): Provider {
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 {
47
58
  return new Provider({
48
59
  id: Identifier.fromKey(data.id),
49
60
  url: data.url,
@@ -56,19 +67,6 @@ export class Provider implements Keyable, Model<ProviderJson> {
56
67
  });
57
68
  }
58
69
 
59
- toJson(): ProviderJson {
60
- return {
61
- id: this.id.key(),
62
- url: this.url,
63
- name: this.name,
64
- version: this.version,
65
- repository_url: this.repositoryUrl,
66
- image_url: this.imageUrl,
67
- description: this.description,
68
- regex: this.regex,
69
- };
70
- }
71
-
72
70
  key(): string {
73
71
  return this.id.key();
74
72
  }
@@ -1,5 +1,4 @@
1
1
  import { Identifier } from '@omujs/omu';
2
- import type { Model } from '@omujs/omu/model.js';
3
2
 
4
3
  export type ReactionJson = {
5
4
  room_id: string;
@@ -8,7 +7,7 @@ export type ReactionJson = {
8
7
  };
9
8
  };
10
9
 
11
- export class Reaction implements Model<ReactionJson> {
10
+ export class Reaction {
12
11
  public roomId: Identifier;
13
12
  public reactions: {
14
13
  [key: string]: number;
@@ -24,17 +23,17 @@ export class Reaction implements Model<ReactionJson> {
24
23
  this.reactions = options.reactions;
25
24
  }
26
25
 
27
- static fromJson(data: ReactionJson): Reaction {
26
+ public static deserialize(data: ReactionJson): Reaction {
28
27
  return new Reaction({
29
28
  roomId: Identifier.fromKey(data.room_id),
30
29
  reactions: data.reactions,
31
30
  });
32
31
  }
33
32
 
34
- toJson(): ReactionJson {
33
+ public static serialize(item: Reaction): ReactionJson {
35
34
  return {
36
- room_id: this.roomId.key(),
37
- reactions: this.reactions,
35
+ room_id: item.roomId.key(),
36
+ reactions: item.reactions,
38
37
  };
39
38
  }
40
39
  }
@@ -1,5 +1,3 @@
1
- import type { Model } from '@omujs/omu/model.js';
2
-
3
1
  export type RoleJson = {
4
2
  id?: string;
5
3
  name: string;
@@ -9,7 +7,7 @@ export type RoleJson = {
9
7
  color?: string;
10
8
  };
11
9
 
12
- export class Role implements Model<RoleJson> {
10
+ export class Role {
13
11
  id?: string;
14
12
  name: string;
15
13
  isOwner: boolean;
@@ -1,6 +1,4 @@
1
- import { Identifier } from '@omujs/omu/identifier.js';
2
- import type { Keyable, Timestamped } from '@omujs/omu/interface.js';
3
- import type { Model } from '@omujs/omu/model.js';
1
+ import { Identifier } from '@omujs/omu';
4
2
 
5
3
  export type MetadataJson = {
6
4
  title?: string;
@@ -27,7 +25,7 @@ export type RoomJson = {
27
25
  created_at: string; // ISO 8601 date string
28
26
  };
29
27
 
30
- export class Room implements Model<RoomJson>, Keyable, Timestamped {
28
+ export class Room {
31
29
  public id: Identifier;
32
30
  public providerId: Identifier;
33
31
  public connected: boolean;
@@ -54,7 +52,7 @@ export class Room implements Model<RoomJson>, Keyable, Timestamped {
54
52
  this.createdAt = options.createdAt;
55
53
  }
56
54
 
57
- static fromJson(options: RoomJson): Room {
55
+ public static deserialize(options: RoomJson): Room {
58
56
  return new Room({
59
57
  id: Identifier.fromKey(options.id),
60
58
  providerId: Identifier.fromKey(options.provider_id),
@@ -66,15 +64,15 @@ export class Room implements Model<RoomJson>, Keyable, Timestamped {
66
64
  });
67
65
  }
68
66
 
69
- toJson(): RoomJson {
67
+ public static serialize(item: Room): RoomJson {
70
68
  return {
71
- id: this.id.key(),
72
- provider_id: this.providerId.key(),
73
- connected: this.connected,
74
- status: this.status,
75
- metadata: this.metadata,
76
- channel_id: this.channelId,
77
- created_at: this.createdAt.toISOString(),
69
+ id: item.id.key(),
70
+ provider_id: item.providerId.key(),
71
+ connected: item.connected,
72
+ status: item.status,
73
+ metadata: item.metadata,
74
+ channel_id: item.channelId,
75
+ created_at: item.createdAt.toISOString(),
78
76
  };
79
77
  }
80
78
 
@@ -1,6 +1,4 @@
1
1
  import { Identifier } from '@omujs/omu';
2
- import type { Keyable } from '@omujs/omu/interface.js';
3
- import type { Model } from '@omujs/omu/model.js';
4
2
 
5
3
  export type Choice = {
6
4
  text: string;
@@ -17,7 +15,7 @@ export type VoteJson = {
17
15
  total: number | null;
18
16
  };
19
17
 
20
- export class Vote implements Keyable, Model<VoteJson> {
18
+ export class Vote {
21
19
  public readonly id: Identifier;
22
20
  public readonly roomId: Identifier;
23
21
  public title: string;
@@ -41,7 +39,7 @@ export class Vote implements Keyable, Model<VoteJson> {
41
39
  this.total = options.total;
42
40
  }
43
41
 
44
- public static fromJson(options: VoteJson): Vote {
42
+ public static deserialize(options: VoteJson): Vote {
45
43
  return new Vote({
46
44
  id: Identifier.fromKey(options.id),
47
45
  roomId: Identifier.fromKey(options.room_id),
@@ -52,14 +50,14 @@ export class Vote implements Keyable, Model<VoteJson> {
52
50
  });
53
51
  }
54
52
 
55
- public toJson(): VoteJson {
53
+ public static serialize(item: Vote): VoteJson {
56
54
  return {
57
- id: this.id.key(),
58
- room_id: this.roomId.key(),
59
- title: this.title,
60
- choices: this.choices,
61
- ended: this.ended,
62
- total: this.total,
55
+ id: item.id.key(),
56
+ room_id: item.roomId.key(),
57
+ title: item.title,
58
+ choices: item.choices,
59
+ ended: item.ended,
60
+ total: item.total,
63
61
  };
64
62
  }
65
63
 
@@ -1,8 +1,9 @@
1
- import { IDENTIFIER } from './const.js';
1
+ import { Identifier } from '@omujs/omu';
2
+ import { PLUGIN_ID } from './const.js';
2
3
 
3
- export const CHAT_PERMISSION_ID = IDENTIFIER;
4
- export const CHAT_READ_PERMISSION_ID = IDENTIFIER.join('chat', 'read');
5
- export const CHAT_WRITE_PERMISSION_ID = IDENTIFIER.join('chat', 'write');
6
- export const CHAT_SEND_PERMISSION_ID = IDENTIFIER.join('chat', 'send');
7
- export const CHAT_CHANNEL_TREE_PERMISSION_ID = IDENTIFIER.join('create_channel_tree');
8
- export const CHAT_REACTION_PERMISSION_ID = IDENTIFIER.join('reaction');
4
+ export const CHAT_PERMISSION_ID: Identifier = PLUGIN_ID;
5
+ export const CHAT_READ_PERMISSION_ID: Identifier = PLUGIN_ID.join('chat', 'read');
6
+ export const CHAT_WRITE_PERMISSION_ID: Identifier = PLUGIN_ID.join('chat', 'write');
7
+ export const CHAT_SEND_PERMISSION_ID: Identifier = PLUGIN_ID.join('chat', 'send');
8
+ export const CHAT_CHANNEL_TREE_PERMISSION_ID: Identifier = PLUGIN_ID.join('create_channel_tree');
9
+ export const CHAT_REACTION_PERMISSION_ID: Identifier = PLUGIN_ID.join('reaction');
package/tsconfig.json CHANGED
@@ -1,7 +1,10 @@
1
1
  {
2
2
  "$schema": "http://json.schemastore.org/tsconfig",
3
- "extends": "../eslint-config/tsconfig.json",
4
- "compilerOptions": {},
3
+ "extends": "../../tsconfig.json",
4
+ "compilerOptions": {
5
+ "isolatedDeclarations": true,
6
+ "declaration": true
7
+ },
5
8
  "compileOnSave": true,
6
9
  "include": [
7
10
  "./src/**/*"