Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4100078
SearchClientFactory.js
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
SearchClientFactory.js
View Options
/**
* Factory for creating search clients
*
* @module SearchClientFactory
*/
const
{
CitizenCommandPaletteSearchClient
}
=
require
(
'../types.js'
);
const
MwRestSearchClient
=
require
(
'./MwRestSearchClient.js'
);
/**
* Registry of available search client factory functions.
* Each factory returns a client instance.
*
* @type {Object.<string, function(mw.Map): CitizenCommandPaletteSearchClient>}
*/
const
searchClientRegistry
=
{
MwRestSearchClient
:
()
=>
new
MwRestSearchClient
()
};
/**
* Create a search client instance based on the configuration.
*
* @return {CitizenCommandPaletteSearchClient}
* @throws {Error} If the configured type is not registered or config is missing.
*/
function
create
()
{
// We don't have any other client type yet
const
clientType
=
'MwRestSearchClient'
;
const
factory
=
searchClientRegistry
[
clientType
];
if
(
!
factory
)
{
// Use mw.log.error in production? Throwing for now.
throw
new
Error
(
`Unknown or unregistered search client type configured:
${
clientType
}
`
);
}
return
factory
();
}
/**
* Register a new search client type dynamically.
* Useful for extensions adding their own search clients.
*
* @param {string} type Unique identifier for the search client type.
* @param {function(mw.Map): CitizenCommandPaletteSearchClient} factory Function that creates the search client instance.
* @throws {Error} If the type is already registered.
*/
function
registerSearchClient
(
type
,
factory
)
{
if
(
searchClientRegistry
[
type
]
)
{
throw
new
Error
(
`Search client type "
${
type
}
" is already registered.`
);
}
searchClientRegistry
[
type
]
=
factory
;
}
module
.
exports
=
{
create
,
registerSearchClient
};
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Aug 18, 16:13 (3 w, 5 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
2a/df/3328862da42ef74186b5b56289b9
Default Alt Text
SearchClientFactory.js (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment