HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux wordpress-ubuntu-s-2vcpu-4gb-fra1-01 5.4.0-169-generic #187-Ubuntu SMP Thu Nov 23 14:52:28 UTC 2023 x86_64
User: root (0)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/delta/wp-content/plugins/better-wp-security/core/packages/data/src/tools/selectors.js
/**
 * External dependencies
 */
import createSelector from 'rememo';
import memize from 'memize';

/**
 * WordPress dependencies
 */
import { createRegistrySelector } from '@wordpress/data';

/**
 * Internal dependencies
 */
import { MODULES_STORE_NAME } from '../index';
import { STORE_NAME } from './constant';

const _combineTools = memize(
	( fromConfig, fromApi ) =>
		fromConfig.map( ( config ) => fromApi[ config.slug ] || config ),
	{ maxSize: 1 }
);

export const getResolvedTools = createRegistrySelector(
	( select ) => ( state ) =>
		_combineTools(
			select( STORE_NAME ).getToolsConfig(),
			state.bySlug
		)
);

export const getTools = createSelector(
	( state ) => state.slugs.map( ( slug ) => state.bySlug[ slug ] ),
	( state ) => [ state.bySlug, state.slugs ]
);

const _transformTools = memize(
	( modules ) => {
		return modules.reduce( ( acc, module ) => {
			for ( const [ slug, config ] of Object.entries( module.tools ) ) {
				acc.push( {
					slug,
					module: module.id,
					toggleable: false,
					schedule: '',
					form: null,
					...config,
				} );
			}

			return acc;
		}, [] );
	},
	{ maxSize: 1 }
);

export const getToolsConfig = createRegistrySelector( ( select ) => () =>
	_transformTools( select( MODULES_STORE_NAME ).getModules() )
);

export const getTool = createRegistrySelector( ( select ) => ( state, tool ) =>
	state.bySlug[ tool ] ||
	select( STORE_NAME )
		.getToolsConfig()
		.find( ( maybe ) => tool === maybe.slug )
);

export function getRunning( state ) {
	return state.running;
}

export function isRunning( state, tool ) {
	return state.running.includes( tool );
}

export function getLastResult( state, tool ) {
	return state.lastResult[ tool ];
}

export function isUpdating( state, tool ) {
	return state.updating.includes( tool );
}

export function getLastError( state, tool ) {
	return state.lastError[ tool ];
}