Skip to content

Commit 8754f03

Browse files
committed
Move JSDoc typedefs to types.ts
1 parent 61d4683 commit 8754f03

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+501
-743
lines changed

src/headless/plugins/adhoc/api.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
/**
2-
* @typedef {import('./utils').AdHocCommand} AdHocCommand
3-
* @typedef {import('./utils').AdHocCommandResult} AdHocCommandResult
4-
*/
51
import log from '../../log.js';
62
import _converse from '../../shared/_converse.js';
73
import api from '../../shared/api/index.js';
@@ -10,11 +6,12 @@ import { parseCommandResult, parseForCommands } from './utils.js';
106

117
const { Strophe, $iq, u, stx } = converse.env;
128

13-
/**
14-
* @typedef {'execute'| 'cancel' |'prev'|'next'|'complete'} AdHocCommandAction
15-
*/
169

1710
export default {
11+
/**
12+
* @typedef {import('./types').AdHocCommandResult} AdHocCommandResult
13+
*/
14+
1815
/**
1916
* The XEP-0050 Ad-Hoc Commands API
2017
*
@@ -64,7 +61,7 @@ export default {
6461
* @method api.adhoc.runCommand
6562
* @param {String} jid
6663
* @param {String} sessionid
67-
* @param {AdHocCommandAction} action
64+
* @param {import('./types').AdHocCommandAction} action
6865
* @param {String} node
6966
* @param {Array<{ [k:string]: string }>} inputs
7067
*/
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { XForm } from '../../shared/types';
2+
3+
export type AdHocCommand = {
4+
action: string;
5+
node: string;
6+
sessionid: string;
7+
status: string;
8+
}
9+
10+
type AdHocCommandResultNote = {
11+
text: string;
12+
type: 'info'|'warn'|'error';
13+
}
14+
15+
export type AdHocCommandAttrs = {
16+
sessionid: string;
17+
actions?: string[];
18+
note?: AdHocCommandResultNote;
19+
}
20+
21+
export type AdHocCommandResult = XForm & AdHocCommandAttrs;
22+
23+
export type AdHocCommandAction = 'execute'| 'cancel' |'prev'|'next'|'complete';

src/headless/plugins/adhoc/utils.js

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,25 @@
1-
/**
2-
* @typedef {import('lit').TemplateResult} TemplateResult
3-
* @typedef {import('../../shared/parsers').XForm} XForm
4-
*/
51
import sizzle from 'sizzle';
62
import converse from '../../shared/api/public.js';
73
import { parseXForm } from '../../shared/parsers.js';
84

95
const { Strophe, u } = converse.env;
106

11-
/**
12-
* @typedef {Object} AdHocCommand
13-
* @property {string} action
14-
* @property {string} node
15-
* @property {string} sessionid
16-
* @property {string} status
17-
*/
18-
197
/**
208
* Given a "result" IQ stanza that contains a list of ad-hoc commands, parse it
219
* and return the list of commands as JSON objects.
2210
* @param {Element} stanza
23-
* @returns {AdHocCommand[]}
11+
* @returns {import('./types').AdHocCommand[]}
2412
*/
2513
export function parseForCommands(stanza) {
2614
const items = sizzle(`query[xmlns="${Strophe.NS.DISCO_ITEMS}"][node="${Strophe.NS.ADHOC}"] item`, stanza);
2715
return items.map(u.getAttributes);
2816
}
2917

30-
/**
31-
* @typedef {Object} AdHocCommandResultNote
32-
* @property {string} text
33-
* @property {'info'|'warn'|'error'} type
34-
*
35-
* @typedef {Object} AdHocCommandAttrs
36-
* @property {string} sessionid
37-
* @property {string[]} [actions]
38-
* @property {AdHocCommandResultNote} [note]
39-
*
40-
* @typedef {XForm & AdHocCommandAttrs} AdHocCommandResult
41-
*/
42-
4318
/**
4419
* Given a "result" IQ stanza containing the outcome of an Ad-hoc command that
4520
* was executed, parse it and return the values as a JSON object.
4621
* @param {Element} iq
47-
* @returns {AdHocCommandResult}
22+
* @returns {import('./types').AdHocCommandResult}
4823
*/
4924
export function parseCommandResult(iq) {
5025
const cmd_el = sizzle(`command[xmlns="${Strophe.NS.ADHOC}"]`, iq).pop();

src/headless/plugins/mam/api.js

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
/**
2-
* @typedef {module:converse-rsm.RSMQueryParameters} RSMQueryParameters
3-
*/
41
import _converse from '../../shared/_converse.js';
52
import api from '../../shared/api/index.js';
63
import converse from '../../shared/api/public.js';
@@ -29,33 +26,16 @@ export default {
2926
* @memberOf _converse.api
3027
*/
3128
archive: {
32-
/**
33-
* @typedef {RSMQueryParameters} MAMFilterParameters
34-
* Filter parmeters which can be used to filter a MAM XEP-0313 archive
35-
* @property String} [end] - A date string in ISO-8601 format, before which messages should be returned. Implies backward paging.
36-
* @property {String} [start] - A date string in ISO-8601 format, after which messages should be returned. Implies forward paging.
37-
* @property {String} [with] - A JID against which to match messages, according to either their `to` or `from` attributes.
38-
* An item in a MUC archive matches if the publisher of the item matches the JID.
39-
* If `with` is omitted, all messages that match the rest of the query will be returned, regardless of to/from
40-
* addresses of each message.
41-
*/
42-
43-
/**
44-
* The options that can be passed in to the {@link _converse.api.archive.query } method
45-
* @typedef {MAMFilterParameters} ArchiveQueryOptions
46-
* @property {boolean} [groupchat=false] - Whether the MAM archive is for a groupchat.
47-
*/
48-
4929
/**
5030
* Query for archived messages.
5131
*
5232
* The options parameter can also be an instance of
5333
* RSM to enable easy querying between results pages.
5434
*
5535
* @method _converse.api.archive.query
56-
* @param {ArchiveQueryOptions} options - An object containing query parameters
36+
* @param {import('./types').ArchiveQueryOptions} options - An object containing query parameters
5737
* @throws {Error} An error is thrown if the XMPP server responds with an error.
58-
* @returns {Promise<MAMQueryResult>} A promise which resolves to a {@link MAMQueryResult} object.
38+
* @returns {Promise<import('./types').MAMQueryResult>}
5939
*
6040
* @example
6141
* // Requesting all archived messages
@@ -299,16 +279,6 @@ export default {
299279
if (set) {
300280
rsm = new RSM({...options, 'xml': set});
301281
}
302-
/**
303-
* @typedef {Object} MAMQueryResult
304-
* @property {Array} messages
305-
* @property {RSM} [rsm] - An instance of {@link RSM}.
306-
* You can call `next()` or `previous()` on this instance,
307-
* to get the RSM query parameters for the next or previous
308-
* page in the result set.
309-
* @property {boolean} [complete]
310-
* @property {Error} [error]
311-
*/
312282
return { messages, rsm, complete };
313283
}
314284
}

src/headless/plugins/mam/types.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { RSM } from '../../shared/rsm';
2+
3+
export type MAMOptions = {
4+
max?: number; // The maximum number of items to return. Defaults to "archived_messages_page_size"
5+
after?: string; // The XEP-0359 stanza ID of a message after which messages should be returned. Implies forward paging.
6+
before?: string; // The XEP-0359 stanza ID of a message before which messages should be returned. Implies backward paging.
7+
end?: string; // A date string in ISO-8601 format, before which messages should be returned. Implies backward paging.
8+
start?: string; // A date string in ISO-8601 format, after which messages should be returned. Implies forward paging.
9+
with?: string; // The JID of the entity with which messages were exchanged.
10+
groupchat?: boolean; // True if archive in groupchat.
11+
};
12+
13+
// XEP-0059 RSM Attributes that can be used to filter query results
14+
type RSMQueryParameters = {
15+
after?: string; // The XEP-0359 stanza ID of a message after which messages should be returned. Implies forward paging.
16+
before?: string; // The XEP-0359 stanza ID of a message before which messages should be returned. Implies backward paging.
17+
index?: number; // The index of the results page to return.
18+
max?: number; // The maximum number of items to return.
19+
};
20+
21+
// Filter parmeters which can be used to filter a MAM XEP-0313 archive
22+
export type MAMFilterParameters = RSMQueryParameters & {
23+
end?: string; // A date string in ISO-8601 format, before which messages should be returned. Implies backward paging.
24+
start?: string; // A date string in ISO-8601 format, after which messages should be returned. Implies forward paging.
25+
with?: string; // A JID against which to match messages, according to either their `to` or `from` attributes.
26+
// An item in a MUC archive matches if the publisher of the item matches the JID.
27+
// If `with` is omitted, all messages that match the rest of the query will be returned, regardless of to/from
28+
// addresses of each message.
29+
};
30+
31+
// The options that can be passed in to the api.archive.query method
32+
export type ArchiveQueryOptions = MAMFilterParameters & {
33+
groupchat?: boolean; // Whether the MAM archive is for a groupchat.
34+
};
35+
36+
export type MAMQueryResult = {
37+
messages: any[];
38+
rsm?: RSM; // You can call `next()` or `previous()` on this,
39+
// to get the RSM query parameters for the next or previous page in the result set.
40+
complete?: boolean;
41+
error?: Error;
42+
};

src/headless/plugins/mam/utils.js

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -138,28 +138,10 @@ export async function handleMAMResult(model, result, query, options, should_page
138138
}
139139
}
140140

141-
/**
142-
* @typedef {Object} MAMOptions
143-
* A map of MAM related options that may be passed to fetchArchivedMessages
144-
* @param {number} [options.max] - The maximum number of items to return.
145-
* Defaults to "archived_messages_page_size"
146-
* @param {string} [options.after] - The XEP-0359 stanza ID of a message
147-
* after which messages should be returned. Implies forward paging.
148-
* @param {string} [options.before] - The XEP-0359 stanza ID of a message
149-
* before which messages should be returned. Implies backward paging.
150-
* @param {string} [options.end] - A date string in ISO-8601 format,
151-
* before which messages should be returned. Implies backward paging.
152-
* @param {string} [options.start] - A date string in ISO-8601 format,
153-
* after which messages should be returned. Implies forward paging.
154-
* @param {string} [options.with] - The JID of the entity with
155-
* which messages were exchanged.
156-
* @param {boolean} [options.groupchat] - True if archive in groupchat.
157-
*/
158-
159141
/**
160142
* Fetch XEP-0313 archived messages based on the passed in criteria.
161143
* @param {ChatBox|MUC} model
162-
* @param {MAMOptions} [options]
144+
* @param {import('./types').MAMOptions} [options]
163145
* @param {('forwards'|'backwards'|null)} [should_page=null] - Determines whether
164146
* this function should recursively page through the entire result set if a limited
165147
* number of results were returned.
@@ -205,7 +187,7 @@ export async function fetchArchivedMessages(model, options = {}, should_page = n
205187
/**
206188
* Create a placeholder message which is used to indicate gaps in the history.
207189
* @param {ChatBox|MUC} model
208-
* @param {MAMOptions} options
190+
* @param {import('./types').MAMOptions} options
209191
* @param {object} result - The RSM result object
210192
*/
211193
async function createPlaceholder(model, options, result) {

src/headless/plugins/muc/message.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import api from '../../shared/api/index.js';
66

77
class MUCMessage extends Message {
88
/**
9-
* @typedef {import('plugins/vcard/utils.js').MUCOccupant} MUCOccupant
9+
* @typedef {import('./occupant').default} MUCOccupant
1010
*/
1111
async initialize () { // eslint-disable-line require-await
1212
if (!this.checkValidity()) return;
@@ -85,7 +85,7 @@ class MUCMessage extends Message {
8585
}
8686

8787
/**
88-
* @param {import('plugins/vcard/utils.js').MUCOccupant} [occupant]
88+
* @param {MUCOccupant} [occupant]
8989
* @return {MUCOccupant}
9090
*/
9191
setOccupant (occupant) {

src/headless/plugins/muc/muc.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ class MUC extends ModelWithMessages(ColorAwareModel(ChatBoxBase)) {
4747
* @typedef {import('./message.js').default} MUCMessage
4848
* @typedef {import('./occupant.js').default} MUCOccupant
4949
* @typedef {import('./affiliations/utils.js').NonOutcastAffiliation} NonOutcastAffiliation
50-
* @typedef {import('./parsers').MemberListItem} MemberListItem
51-
* @typedef {import('../chat/types.ts').MessageAttributes} MessageAttributes
52-
* @typedef {import('./types.ts').MUCMessageAttributes} MUCMessageAttributes
50+
* @typedef {import('./types').MemberListItem} MemberListItem
51+
* @typedef {import('../chat/types').MessageAttributes} MessageAttributes
52+
* @typedef {import('./types').MUCMessageAttributes} MUCMessageAttributes
5353
* @typedef {module:shared.converse.UserMessage} UserMessage
5454
* @typedef {import('strophe.js').Builder} Builder
5555
* @typedef {import('../../shared/parsers').StanzaParseError} StanzaParseError

src/headless/plugins/muc/occupants.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,10 @@ class MUCOccupants extends Collection {
126126
}
127127

128128
/**
129-
* @typedef { Object} OccupantData
130-
* @property { String } [jid]
131-
* @property { String } [nick]
132-
* @property { String } [occupant_id] - The XEP-0421 unique occupant id
129+
* @typedef {Object} OccupantData
130+
* @property {String} [jid]
131+
* @property {String} [nick]
132+
* @property {String} [occupant_id] - The XEP-0421 unique occupant id
133133
*/
134134
/**
135135
* Try to find an existing occupant based on the provided

src/headless/plugins/muc/parsers.js

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @module:plugin-muc-parsers
33
* @typedef {import('../muc/muc.js').default} MUC
4-
* @typedef {import('./types.ts').MUCMessageAttributes} MUCMessageAttributes
4+
* @typedef {import('./types').MUCMessageAttributes} MUCMessageAttributes
55
*/
66
import dayjs from 'dayjs';
77
import _converse from '../../shared/_converse.js';
@@ -250,15 +250,8 @@ export async function parseMUCMessage (stanza, chatbox) {
250250
* Given an IQ stanza with a member list, create an array of objects containing
251251
* known member data (e.g. jid, nick, role, affiliation).
252252
*
253-
* @typedef {Object} MemberListItem
254-
* Either the JID or the nickname (or both) will be available.
255-
* @property {string} affiliation
256-
* @property {string} [role]
257-
* @property {string} [jid]
258-
* @property {string} [nick]
259-
*
260253
* @param {Element} iq
261-
* @returns {MemberListItem[]}
254+
* @returns {import('./types').MemberListItem[]}
262255
*/
263256
export function parseMemberListIQ (iq) {
264257
return sizzle(`query[xmlns="${Strophe.NS.MUC_ADMIN}"] item`, iq).map(
@@ -289,30 +282,11 @@ export function parseMemberListIQ (iq) {
289282

290283
/**
291284
* Parses a passed in MUC presence stanza and returns an object of attributes.
292-
* @method parseMUCPresence
293285
* @param {Element} stanza - The presence stanza
294286
* @param {MUC} chatbox
295-
* @returns {MUCPresenceAttributes}
287+
* @returns {import('./types').MUCPresenceAttributes}
296288
*/
297289
export function parseMUCPresence (stanza, chatbox) {
298-
/**
299-
* Object representing a XEP-0371 Hat
300-
* @typedef {Object} MUCHat
301-
* @property {string} title
302-
* @property {string} uri
303-
*
304-
* The object which {@link parseMUCPresence} returns
305-
* @typedef {Object} MUCPresenceAttributes
306-
* @property {string} show
307-
* @property {Array<MUCHat>} hats - An array of XEP-0317 hats
308-
* @property {Array<string>} states
309-
* @property {String} from - The sender JID (${muc_jid}/${nick})
310-
* @property {String} nick - The nickname of the sender
311-
* @property {String} occupant_id - The XEP-0421 occupant ID
312-
* @property {String} type - The type of presence
313-
* @property {String} [jid]
314-
* @property {boolean} [is_me]
315-
*/
316290
const from = stanza.getAttribute('from');
317291
const type = stanza.getAttribute('type');
318292
const data = {

0 commit comments

Comments
 (0)