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/patchstack/selectors.js
/**
 * External dependencies
 */
import createSelector from 'rememo';
import { filter, find, get } from 'lodash';

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

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

export const getPatchstackVulnerabilities = createRegistrySelector( ( select ) => () =>
	select( STORE_NAME ).getQueryResults( 'main' )
);

export function getPatchstackVulnerability( state, id ) {
	return state.byId[ id ];
}

export const getQueryResults = createSelector(
	( state, queryId ) => {
		const ids = get( state, [ 'queries', queryId, 'ids' ], [] );
		const byId = state.byId;

		const length = ids.length;
		const items = new Array( length );
		let index = -1;

		while ( ++index < length ) {
			const entry = byId[ ids[ index ] ];

			if ( entry ) {
				items[ index ] = entry.item;
			}
		}

		return items;
	},
	( state, queryId ) => [ state.queries[ queryId ], state.byId ]
);

export function getQueryHeaderLink( state, queryId, rel ) {
	return find( get( state, [ 'queries', queryId, 'links' ], [] ), { rel: [ rel ] } );
}

export function getQueryHeaderLinks( state, queryId, rel ) {
	return filter( get( state, [ 'queries', queryId, 'links' ], [] ), { rel: [ rel ] } );
}

export function getQueryHeader( state, queryId, header ) {
	return get( state, [ 'queries', queryId, 'headers', header ] );
}

export function getQueryParams( state, queryId ) {
	return get( state, [ 'queryParams', queryId ] );
}

export function queryHasNextPage( state, queryId ) {
	return getQueryHeaderLink( state, queryId, 'next' );
}

export function queryHasPrevPage( state, queryId ) {
	return !! getQueryHeaderLink( state, queryId, 'prev' );
}

export function getLastFetchError( state, queryId ) {
	return get( state, [ 'errors', queryId ] );
}

export function isQuerying( state, queryId ) {
	return state.querying.includes( queryId );
}