Page MenuHomeWickedGov Phorge

translationentitysearch.api.js
No OneTemporary

Size
1 KB
Referenced Files
None
Subscribers
None

translationentitysearch.api.js

'use strict';
const api = new mw.Api();
const ACTION = 'translationentitysearch';
/** Simple request tracker to avoid duplicate API calls */
const requestTracker = {
// TODO: Add a max limit or expiry time in the future.
/** @type {Object.<string,mw.Api~AbortablePromise>} Pending requests by request signature */
pendingRequests: {},
/**
* Execute API request or return existing promise if identical request is pending
*
* @param {Object} params Request parameters
* @return {mw.Api~AbortablePromise}
*/
execute( params ) {
const key = JSON.stringify( params );
// If we already have this exact request in progress, return its promise
if ( this.pendingRequests[ key ] ) {
return this.pendingRequests[ key ];
}
// Make the API call and store the promise
const promise = api.get( params )
.then( ( results ) => results.translationentitysearch || null )
.catch( ( error ) => {
delete this.pendingRequests[ key ];
throw error;
} );
// Store the promise
this.pendingRequests[ key ] = promise;
return promise;
}
};
/**
* Fetch entities matching the specified criteria
*
* @param {Object} request
* @param {string} request.searchTerm
* @param {('groups'|'messages')[]} request.entityTypes
* @param {('aggregate-groups'|'message-bundles'|'translatable-pages')[]} request.groupTypes
* @param {number} request.limit
* @return {mw.Api~AbortablePromise}
*/
function get( { searchTerm, entityTypes, groupTypes, limit } ) {
return requestTracker.execute( {
action: ACTION,
query: searchTerm,
entitytype: entityTypes,
grouptypes: groupTypes,
limit
} );
}
module.exports = get;

File Metadata

Mime Type
text/plain
Expires
Tue, Aug 18, 16:14 (3 w, 4 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
91/11/a48b9ba89bbe6d47cc0bc54a0250
Default Alt Text
translationentitysearch.api.js (1 KB)

Event Timeline