@sockethub/irc2as 4.0.0-alpha.3 → 4.0.0-alpha.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 CHANGED
@@ -1,10 +1,10 @@
1
1
  # IRC2AS
2
2
 
3
- Parses the IRC protocol into ActivtyStreams objects.
3
+ Parses the IRC protocol into ActivityStreams objects.
4
4
 
5
5
  ## Overview
6
6
 
7
- Currently a very simple library to parse incoming IRC protocol messages and generate activity
7
+ Currently, a very simple library to parse incoming IRC protocol messages and generate activity
8
8
  streams. The activity streams are not fully AS2.0 compliant, but aim to be shaped in the spirit
9
9
  of them, and as time goes on hopefully become more compliant (PRs & feedback welcome).
10
10
 
@@ -45,4 +45,3 @@ MIT
45
45
  ## Maintainer
46
46
 
47
47
  Nick Jennings <nick@silverbucket.net>
48
-
package/package.json CHANGED
@@ -1,27 +1,11 @@
1
1
  {
2
2
  "name": "@sockethub/irc2as",
3
- "version": "4.0.0-alpha.3",
3
+ "version": "4.0.0-alpha.5",
4
4
  "description": "IRC to ActivityStreams objects",
5
+ "type": "module",
5
6
  "main": "src/index.js",
6
- "directories": {
7
- "test": "test"
8
- },
9
- "dependencies": {
10
- "debug": "^4.3.1",
11
- "fast-deep-equal": "^3.1.1"
12
- },
13
- "devDependencies": {
14
- "@sockethub/schemas": "^3.0.0-alpha.3",
15
- "c8": "7.11.0",
16
- "chai": "4.3.6",
17
- "mocha": "9.2.1"
18
- },
19
- "scripts": {
20
- "clean": "npx rimraf coverage",
21
- "clean:deps": "npx rimraf node_modules",
22
- "compliance": "yarn run test && yarn run coverage",
23
- "test": "c8 mocha src/**.test.js",
24
- "coverage": "c8 check-coverage --statements 90 --branches 90 --functions 95 --lines 90"
7
+ "engines": {
8
+ "bun": ">=1.2"
25
9
  },
26
10
  "repository": {
27
11
  "type": "git",
@@ -40,5 +24,12 @@
40
24
  "url": "https://github.com/sockethub/sockethub/issues"
41
25
  },
42
26
  "homepage": "https://github.com/sockethub/sockethub/tree/master/packages/irc2as",
43
- "gitHead": "f02238a478b7ffd3f31d8deea292eb67e630a86b"
27
+ "dependencies": {
28
+ "debug": "^4.4.0",
29
+ "fast-deep-equal": "^3.1.3"
30
+ },
31
+ "devDependencies": {
32
+ "@sockethub/schemas": "3.0.0-alpha.5"
33
+ },
34
+ "gitHead": "341ea9eeca6afd1442fe6e01457bc21d112b91a4"
44
35
  }
package/src/as-emitter.js CHANGED
@@ -1,274 +1,277 @@
1
- const EVENT_INCOMING = 'incoming',
2
- EVENT_ERROR = 'error';
1
+ const EVENT_INCOMING = "incoming";
2
+ const EVENT_ERROR = "error";
3
3
 
4
- class ASTemplates {
5
- constructor(events, server) {
6
- this.server = server;
7
- this.events = events;
8
- }
4
+ export class ASEmitter {
5
+ constructor(events, server) {
6
+ this.server = server;
7
+ this.events = events;
8
+ }
9
9
 
10
- emitEvent(code, asObject) {
11
- if ((typeof asObject === 'object') && (! asObject.published)) {
12
- asObject.published = `${Date.now()}`;
10
+ emitEvent(code, asObject) {
11
+ if (typeof asObject === "object" && !asObject.published) {
12
+ asObject.published = `${Date.now()}`;
13
+ }
14
+ this.events.emit(code, asObject);
13
15
  }
14
- this.events.emit(code, asObject);
15
- }
16
16
 
17
- __generalError(nick, content) {
18
- return {
19
- context: 'irc',
20
- type: 'update',
21
- actor: {
22
- type: 'person',
23
- id: nick + '@' + this.server,
24
- name: nick
25
- },
26
- target: {
27
- type: 'service',
28
- id: this.server
29
- },
30
- error: content
31
- };
32
- }
17
+ __generalError(nick, content) {
18
+ return {
19
+ context: "irc",
20
+ type: "update",
21
+ actor: {
22
+ type: "person",
23
+ id: `${nick}@${this.server}`,
24
+ name: nick,
25
+ },
26
+ target: {
27
+ type: "service",
28
+ id: this.server,
29
+ },
30
+ error: content,
31
+ };
32
+ }
33
33
 
34
- presence(nick, role, channel) {
35
- this.emitEvent(EVENT_INCOMING, {
36
- context: 'irc',
37
- type: 'update',
38
- actor: {
39
- type: 'person',
40
- id: `${nick}@${this.server}`,
41
- name: nick,
42
- },
43
- target: {
44
- type: 'room',
45
- id: this.server + '/' + channel,
46
- name: channel
47
- },
48
- object: {
49
- type: 'presence',
50
- role: role
51
- }
52
- });
53
- };
34
+ presence(nick, role, channel) {
35
+ this.emitEvent(EVENT_INCOMING, {
36
+ context: "irc",
37
+ type: "update",
38
+ actor: {
39
+ type: "person",
40
+ id: `${nick}@${this.server}`,
41
+ name: nick,
42
+ },
43
+ target: {
44
+ type: "room",
45
+ id: `${this.server}/${channel}`,
46
+ name: channel,
47
+ },
48
+ object: {
49
+ type: "presence",
50
+ role: role,
51
+ },
52
+ });
53
+ }
54
54
 
55
- channelError(channel, nick, content) {
56
- this.emitEvent(EVENT_ERROR, {
57
- context: 'irc',
58
- type: 'update',
59
- actor: {
60
- type: 'person',
61
- id: nick + '@' + this.server
62
- },
63
- target: {
64
- type: 'room',
65
- id: this.server + '/' + channel
66
- },
67
- error: content
68
- });
69
- }
55
+ channelError(channel, nick, content) {
56
+ this.emitEvent(EVENT_ERROR, {
57
+ context: "irc",
58
+ type: "update",
59
+ actor: {
60
+ type: "person",
61
+ id: `${nick}@${this.server}`,
62
+ },
63
+ target: {
64
+ type: "room",
65
+ id: `${this.server}/${channel}`,
66
+ },
67
+ error: content,
68
+ });
69
+ }
70
70
 
71
- nickError(nick, content) {
72
- this.emitEvent(EVENT_ERROR, this.__generalError(nick, content));
73
- }
71
+ nickError(nick, content) {
72
+ this.emitEvent(EVENT_ERROR, this.__generalError(nick, content));
73
+ }
74
74
 
75
- notice(nick, content) {
76
- this.emitEvent(EVENT_INCOMING, {
77
- context: 'irc',
78
- type: 'send',
79
- actor: {
80
- type: 'service',
81
- id: this.server
82
- },
83
- object: {
84
- type: 'message',
85
- content: content
86
- },
87
- target: {
88
- type: 'person',
89
- id: nick + '@' + this.server,
90
- name: nick
91
- }
92
- });
93
- }
75
+ notice(nick, content) {
76
+ this.emitEvent(EVENT_INCOMING, {
77
+ context: "irc",
78
+ type: "send",
79
+ actor: {
80
+ type: "service",
81
+ id: this.server,
82
+ },
83
+ object: {
84
+ type: "message",
85
+ content: content,
86
+ },
87
+ target: {
88
+ type: "person",
89
+ id: `${nick}@${this.server}`,
90
+ name: nick,
91
+ },
92
+ });
93
+ }
94
94
 
95
- serviceError(nick, content) {
96
- this.emitEvent(EVENT_ERROR, this.__generalError(nick, content));
97
- }
95
+ serviceError(nick, content) {
96
+ this.emitEvent(EVENT_ERROR, this.__generalError(nick, content));
97
+ }
98
98
 
99
- joinError(nick) {
100
- this.emitEvent(EVENT_ERROR, {
101
- context: 'irc',
102
- type: 'join',
103
- actor: {
104
- id: this.server,
105
- type: 'service'
106
- },
107
- error: 'no such channel ' + nick,
108
- target: {
109
- id: nick + '@' + this.server,
110
- type: 'person'
111
- }
112
- });
113
- }
99
+ joinError(nick) {
100
+ this.emitEvent(EVENT_ERROR, {
101
+ context: "irc",
102
+ type: "join",
103
+ actor: {
104
+ id: this.server,
105
+ type: "service",
106
+ },
107
+ error: `no such channel ${nick}`,
108
+ target: {
109
+ id: `${nick}@${this.server}`,
110
+ type: "person",
111
+ },
112
+ });
113
+ }
114
114
 
115
- topicChange(channel, nick, content) {
116
- this.emitEvent(EVENT_INCOMING, {
117
- context: 'irc',
118
- type: 'update',
119
- actor: {
120
- type: 'person',
121
- id: nick + '@' + this.server,
122
- name: nick
123
- },
124
- target: {
125
- type: 'room',
126
- id: this.server + '/' + channel,
127
- name: channel
128
- },
129
- object: {
130
- type: 'topic',
131
- content: content
132
- }
133
- });
134
- }
115
+ topicChange(channel, nick, content) {
116
+ this.emitEvent(EVENT_INCOMING, {
117
+ context: "irc",
118
+ type: "update",
119
+ actor: {
120
+ type: "person",
121
+ id: `${nick}@${this.server}`,
122
+ name: nick,
123
+ },
124
+ target: {
125
+ type: "room",
126
+ id: `${this.server}/${channel}`,
127
+ name: channel,
128
+ },
129
+ object: {
130
+ type: "topic",
131
+ content: content,
132
+ },
133
+ });
134
+ }
135
135
 
136
- joinRoom(channel, nick) {
137
- this.emitEvent(EVENT_INCOMING, {
138
- context: 'irc',
139
- type: 'join',
140
- actor: {
141
- type: 'person',
142
- id: nick + '@' + this.server,
143
- name: nick
144
- },
145
- target: {
146
- type: 'room',
147
- id: this.server + '/' + channel,
148
- name: channel
149
- }
150
- });
151
- }
136
+ joinRoom(channel, nick) {
137
+ this.emitEvent(EVENT_INCOMING, {
138
+ context: "irc",
139
+ type: "join",
140
+ actor: {
141
+ type: "person",
142
+ id: `${nick}@${this.server}`,
143
+ name: nick,
144
+ },
145
+ target: {
146
+ type: "room",
147
+ id: `${this.server}/${channel}`,
148
+ name: channel,
149
+ },
150
+ });
151
+ }
152
152
 
153
- userQuit(nick) {
154
- this.emitEvent(EVENT_INCOMING, {
155
- context: 'irc',
156
- type: 'leave',
157
- actor: {
158
- type: 'person',
159
- id: nick + '@' + this.server,
160
- name: nick
161
- },
162
- target: {
163
- type: 'service',
164
- id: this.server
165
- },
166
- object: {
167
- type: 'message',
168
- content: 'user has quit'
169
- }
170
- });
171
- }
153
+ userQuit(nick) {
154
+ this.emitEvent(EVENT_INCOMING, {
155
+ context: "irc",
156
+ type: "leave",
157
+ actor: {
158
+ type: "person",
159
+ id: `${nick}@${this.server}`,
160
+ name: nick,
161
+ },
162
+ target: {
163
+ type: "service",
164
+ id: this.server,
165
+ },
166
+ object: {
167
+ type: "message",
168
+ content: "user has quit",
169
+ },
170
+ });
171
+ }
172
172
 
173
- userPart(channel, nick) {
174
- this.emitEvent(EVENT_INCOMING, {
175
- context: 'irc',
176
- type: 'leave',
177
- actor: {
178
- type: 'person',
179
- id: nick + '@' + this.server,
180
- name: nick
181
- },
182
- target: {
183
- type: 'room',
184
- id: this.server + '/' + channel,
185
- name: channel
186
- },
187
- object: {
188
- type: 'message',
189
- content: 'user has left the channel'
190
- }
191
- });
192
- }
173
+ userPart(channel, nick) {
174
+ this.emitEvent(EVENT_INCOMING, {
175
+ context: "irc",
176
+ type: "leave",
177
+ actor: {
178
+ type: "person",
179
+ id: `${nick}@${this.server}`,
180
+ name: nick,
181
+ },
182
+ target: {
183
+ type: "room",
184
+ id: `${this.server}/${channel}`,
185
+ name: channel,
186
+ },
187
+ object: {
188
+ type: "message",
189
+ content: "user has left the channel",
190
+ },
191
+ });
192
+ }
193
193
 
194
- privMsg(nick, target, content) {
195
- let type, message;
196
- if (content.startsWith('+\u0001ACTION ')) {
197
- type = 'me';
198
- message = content.split(/^\+\u0001ACTION\s+/)[1].split(/\u0001$/)[0];
199
- } else {
200
- type = 'message';
201
- message = content;
194
+ privMsg(nick, target, content) {
195
+ let type;
196
+ let message;
197
+ if (content.startsWith("+\u0001ACTION ")) {
198
+ type = "me";
199
+ message = content
200
+ // biome-ignore lint/suspicious/noControlCharactersInRegex: <explanation>
201
+ .split(/^\+\u0001ACTION\s+/)[1]
202
+ // biome-ignore lint/suspicious/noControlCharactersInRegex: <explanation>
203
+ .split(/\u0001$/)[0];
204
+ } else {
205
+ type = "message";
206
+ message = content;
207
+ }
208
+ this.emitEvent(EVENT_INCOMING, {
209
+ context: "irc",
210
+ type: "send",
211
+ actor: {
212
+ type: "person",
213
+ id: `${nick}@${this.server}`,
214
+ name: nick,
215
+ },
216
+ target: {
217
+ type: target.startsWith("#") ? "room" : "person",
218
+ id: `${this.server}/${target}`,
219
+ name: target,
220
+ },
221
+ object: {
222
+ type: type,
223
+ content: message,
224
+ },
225
+ });
202
226
  }
203
- this.emitEvent(EVENT_INCOMING, {
204
- context: 'irc',
205
- type: 'send',
206
- actor: {
207
- type: 'person',
208
- id: nick + '@' + this.server,
209
- name: nick
210
- },
211
- target: {
212
- type: target.startsWith('#') ? "room" : "person",
213
- id: this.server + '/' + target,
214
- name: target
215
- },
216
- object: {
217
- type: type,
218
- content: message
219
- }
220
- });
221
- }
222
227
 
223
- role(type, nick, target, role, channel) {
224
- this.emitEvent(EVENT_INCOMING, {
225
- context: 'irc',
226
- type: type,
227
- actor: {
228
- type: 'person',
229
- id: nick + '@' + this.server,
230
- name: nick
231
- },
232
- target: {
233
- type: 'person',
234
- id: target + '@' + this.server,
235
- name: target
236
- },
237
- object: {
238
- type: "relationship",
239
- "relationship": 'role',
240
- "subject": {
241
- type: 'presence',
242
- role: role
243
- },
244
- "object": {
245
- type: 'room',
246
- id: this.server + '/' + channel,
247
- name: channel
248
- }
249
- }
250
- });
251
- }
228
+ role(type, nick, target, role, channel) {
229
+ this.emitEvent(EVENT_INCOMING, {
230
+ context: "irc",
231
+ type: type,
232
+ actor: {
233
+ type: "person",
234
+ id: `${nick}@${this.server}`,
235
+ name: nick,
236
+ },
237
+ target: {
238
+ type: "person",
239
+ id: `${target}@${this.server}`,
240
+ name: target,
241
+ },
242
+ object: {
243
+ type: "relationship",
244
+ relationship: "role",
245
+ subject: {
246
+ type: "presence",
247
+ role: role,
248
+ },
249
+ object: {
250
+ type: "room",
251
+ id: `${this.server}/${channel}`,
252
+ name: channel,
253
+ },
254
+ },
255
+ });
256
+ }
252
257
 
253
- nickChange(nick, content) {
254
- this.emitEvent(EVENT_INCOMING, {
255
- context: 'irc',
256
- type: 'update',
257
- actor: {
258
- type: 'person',
259
- id: nick + '@' + this.server,
260
- name: nick
261
- },
262
- target: {
263
- type: 'person',
264
- id: content + '@' + this.server,
265
- name: content
266
- },
267
- object: {
268
- type: 'address'
269
- }
270
- });
271
- }
258
+ nickChange(nick, content) {
259
+ this.emitEvent(EVENT_INCOMING, {
260
+ context: "irc",
261
+ type: "update",
262
+ actor: {
263
+ type: "person",
264
+ id: `${nick}@${this.server}`,
265
+ name: nick,
266
+ },
267
+ target: {
268
+ type: "person",
269
+ id: `${content}@${this.server}`,
270
+ name: content,
271
+ },
272
+ object: {
273
+ type: "address",
274
+ },
275
+ });
276
+ }
272
277
  }
273
-
274
- module.exports = ASTemplates;