Pārlūkot izejas kodu

Move type into types.ts

JC Brand 4 mēneši atpakaļ
vecāks
revīzija
e07e65ae40

+ 2 - 13
src/headless/plugins/muc/occupants.js

@@ -124,24 +124,13 @@ class MUCOccupants extends Collection {
     }
 
     /**
-     * @typedef {Object} OccupantData
-     * @property {String} [jid]
-     * @property {String} [nick]
-     * @property {String} [occupant_id] - The XEP-0421 unique occupant id
-     */
-    /**
-     * Try to find an existing occupant based on the provided
-     * @link { OccupantData } object.
-     *
+     * Try to find an existing occupant based on the provided {@link OccupantData} object.
      * Fetching the user by `occupant_id` is the quickest, O(1),
      * since it's a dictionary lookup.
-     *
      * Fetching by jid or nick is O(n), since it requires traversing an array.
-     *
      * Lookup by occupant_id is done first, then jid, and then nick.
      *
-     * @method _converse.MUCOccupants#findOccupant
-     * @param {OccupantData} data
+     * @param {import('./types').OccupantData} data
      */
     findOccupant (data) {
         if (data.occupant_id) {

+ 7 - 0
src/headless/plugins/muc/types.ts

@@ -116,3 +116,10 @@ export type MUCPresenceAttributes = MUCPresenceItemAttributes & {
     status?: string;
     type: string; // The type of presence
 };
+
+
+export type OccupantData = {
+    jid?: string;
+    nick?: string;
+    occupant_id?: string; // The XEP-0421 unique occupant id
+};

+ 3 - 21
src/headless/types/plugins/muc/occupants.d.ts

@@ -15,33 +15,15 @@ declare class MUCOccupants extends Collection {
     get model(): typeof MUCOccupant;
     fetchMembers(): Promise<void>;
     /**
-     * @typedef {Object} OccupantData
-     * @property {String} [jid]
-     * @property {String} [nick]
-     * @property {String} [occupant_id] - The XEP-0421 unique occupant id
-     */
-    /**
-     * Try to find an existing occupant based on the provided
-     * @link { OccupantData } object.
-     *
+     * Try to find an existing occupant based on the provided {@link OccupantData} object.
      * Fetching the user by `occupant_id` is the quickest, O(1),
      * since it's a dictionary lookup.
-     *
      * Fetching by jid or nick is O(n), since it requires traversing an array.
-     *
      * Lookup by occupant_id is done first, then jid, and then nick.
      *
-     * @method _converse.MUCOccupants#findOccupant
-     * @param {OccupantData} data
+     * @param {import('./types').OccupantData} data
      */
-    findOccupant(data: {
-        jid?: string;
-        nick?: string;
-        /**
-         * - The XEP-0421 unique occupant id
-         */
-        occupant_id?: string;
-    }): any;
+    findOccupant(data: import("./types").OccupantData): any;
     /**
      * Get the {@link MUCOccupant} instance which
      * represents the current user.

+ 5 - 0
src/headless/types/plugins/muc/types.d.ts

@@ -83,5 +83,10 @@ export type MUCPresenceAttributes = MUCPresenceItemAttributes & {
     status?: string;
     type: string;
 };
+export type OccupantData = {
+    jid?: string;
+    nick?: string;
+    occupant_id?: string;
+};
 export {};
 //# sourceMappingURL=types.d.ts.map

+ 2 - 3
src/headless/types/utils/index.d.ts

@@ -32,9 +32,9 @@ declare const _default: {
     isImageURL(url: any): any;
     isEncryptedFileURL(url: any): any;
     getMediaURLsMetadata(text: string, offset?: number): {
-        media_urls?: MediaURLMetadata[];
+        media_urls?: import("./types.js").MediaURLMetadata[];
     };
-    getMediaURLs(arr: Array<MediaURLMetadata>, text: string, offset?: number): MediaURLData[];
+    getMediaURLs(arr: Array<import("./types.js").MediaURLMetadata>, text: string, offset?: number): import("./types.js").MediaURLData[];
     firstCharToUpperCase(text: string): string;
     getLongestSubstring(string: string, candidates: string[]): string;
     isString(s: any): boolean;
@@ -122,7 +122,6 @@ declare function shouldCreateMessage(attrs: any): any;
  * @param {boolean} [cancelable]
  */
 declare function triggerEvent(el: Element, name: string, type?: string, bubbles?: boolean, cancelable?: boolean): void;
-import * as url from './url.js';
 import * as session from './session.js';
 import { Model } from '@converse/skeletor';
 import * as init from './init.js';

+ 19 - 0
src/headless/types/utils/types.d.ts

@@ -2,4 +2,23 @@ export type Credentials = {
     jid: string;
     password: string;
 };
+export type ProcessStringOptions = {
+    start?: RegExp;
+    end?: RegExp;
+    trim?: RegExp;
+    parens?: RegExp;
+    ignoreHtml?: boolean;
+    ignore?: RegExp;
+};
+export type MediaURLMetadata = {
+    is_audio?: boolean;
+    is_image?: boolean;
+    is_video?: boolean;
+    is_encrypted?: boolean;
+    end?: number;
+    start?: number;
+};
+export type MediaURLData = MediaURLMetadata & {
+    url: string;
+};
 //# sourceMappingURL=types.d.ts.map

+ 5 - 37
src/headless/types/utils/url.d.ts

@@ -24,52 +24,20 @@ export function isAudioURL(url: any): boolean;
 export function isVideoURL(url: any): boolean;
 export function isImageURL(url: any): any;
 export function isEncryptedFileURL(url: any): any;
-/**
- * @typedef {Object} MediaURLMetadata
- * An object representing the metadata of a URL found in a chat message
- * The actual URL is not saved, it can be extracted via the `start` and `end` indexes.
- * @property {boolean} [is_audio]
- * @property {boolean} [is_image]
- * @property {boolean} [is_video]
- * @property {boolean} [is_encrypted]
- * @property {number} [end]
- * @property {number} [start]
- */
-/**
- * An object representing a URL found in a chat message
- * @typedef {MediaURLMetadata} MediaURLData
- * @property {string} url
- */
 /**
  * @param {string} text
  * @param {number} offset
- * @returns {{media_urls?: MediaURLMetadata[]}}
+ * @returns {{media_urls?: import("./types").MediaURLMetadata[]}}
  */
 export function getMediaURLsMetadata(text: string, offset?: number): {
-    media_urls?: MediaURLMetadata[];
+    media_urls?: import("./types").MediaURLMetadata[];
 };
 /**
  * Given an array of {@link MediaURLMetadata} objects and text, return an
  * array of {@link MediaURL} objects.
- * @param {Array<MediaURLMetadata>} arr
+ * @param {Array<import("./types").MediaURLMetadata>} arr
  * @param {string} text
- * @returns {MediaURLData[]}
- */
-export function getMediaURLs(arr: Array<MediaURLMetadata>, text: string, offset?: number): MediaURLData[];
-/**
- * An object representing the metadata of a URL found in a chat message
- * The actual URL is not saved, it can be extracted via the `start` and `end` indexes.
- */
-export type MediaURLMetadata = {
-    is_audio?: boolean;
-    is_image?: boolean;
-    is_video?: boolean;
-    is_encrypted?: boolean;
-    end?: number;
-    start?: number;
-};
-/**
- * An object representing a URL found in a chat message
+ * @returns {import("./types").MediaURLData[]}
  */
-export type MediaURLData = MediaURLMetadata;
+export function getMediaURLs(arr: Array<import("./types").MediaURLMetadata>, text: string, offset?: number): import("./types").MediaURLData[];
 //# sourceMappingURL=url.d.ts.map

+ 23 - 1
src/headless/utils/types.ts

@@ -1,4 +1,26 @@
 export type Credentials = {
     jid: string;
     password: string;
-}
+};
+
+export type ProcessStringOptions = {
+    start?: RegExp;
+    end?: RegExp;
+    trim?: RegExp;
+    parens?: RegExp;
+    ignoreHtml?: boolean;
+    ignore?: RegExp;
+};
+
+export type MediaURLMetadata = {
+    is_audio?: boolean;
+    is_image?: boolean;
+    is_video?: boolean;
+    is_encrypted?: boolean;
+    end?: number;
+    start?: number;
+};
+
+export type MediaURLData = MediaURLMetadata & {
+    url: string;
+};

+ 3 - 21
src/headless/utils/url.js

@@ -73,28 +73,10 @@ export function isEncryptedFileURL (url) {
     return url.startsWith('aesgcm://');
 }
 
-/**
- * @typedef {Object} MediaURLMetadata
- * An object representing the metadata of a URL found in a chat message
- * The actual URL is not saved, it can be extracted via the `start` and `end` indexes.
- * @property {boolean} [is_audio]
- * @property {boolean} [is_image]
- * @property {boolean} [is_video]
- * @property {boolean} [is_encrypted]
- * @property {number} [end]
- * @property {number} [start]
- */
-
-/**
- * An object representing a URL found in a chat message
- * @typedef {MediaURLMetadata} MediaURLData
- * @property {string} url
- */
-
 /**
  * @param {string} text
  * @param {number} offset
- * @returns {{media_urls?: MediaURLMetadata[]}}
+ * @returns {{media_urls?: import("./types").MediaURLMetadata[]}}
  */
 export function getMediaURLsMetadata (text, offset=0) {
     const objs = [];
@@ -138,9 +120,9 @@ export function getMediaURLsMetadata (text, offset=0) {
 /**
  * Given an array of {@link MediaURLMetadata} objects and text, return an
  * array of {@link MediaURL} objects.
- * @param {Array<MediaURLMetadata>} arr
+ * @param {Array<import("./types").MediaURLMetadata>} arr
  * @param {string} text
- * @returns {MediaURLData[]}
+ * @returns {import("./types").MediaURLData[]}
  */
 export function getMediaURLs (arr, text, offset=0) {
     return arr.map(o => {