Class: SettingsCache

SettingsCache

SettingGateway's driver to make new instances of it, with the purpose to handle different databases simultaneously.

new SettingsCache(client)

Parameters:
Name Type Description
client KlasaClient The Klasa client
Source:
lib/settings/SettingsCache.js#L12

Properties


<readonly> defaultDataSchema

The data schema Klasa uses for guild settings.
Source:
lib/settings/SettingsCache.js#L85

guilds :SettingGateway

The SettingGateway instance created to handle guild settings.
Type:
Source:
lib/settings/SettingsCache.js#L30

resolver :SettingResolver

The resolver instance this SettingGateway uses to parse the data.
Type:
Source:
lib/settings/SettingsCache.js#L24

Methods


<async> add(name, validateFunction [, schema])

Add a new instance of SettingGateway, with its own validateFunction and schema.
Parameters:
Name Type Argument Default Description
name string The name for the new instance.
validateFunction function The function that validates the input.
schema Object <optional>
{} The schema.
Source:
lib/settings/SettingsCache.js#L57
Returns:
Type
SettingGateway
Example
// Add a new SettingGateway instance, called 'users', which input takes users, and stores a quote which is a string between 2 and 140 characters.
const validate = async function(resolver, user) {
	 const result = await resolver.user(user);
	 if (!result) throw 'The parameter <User> expects either a User ID or a User Object.';
	 return result;
};
const schema = {
	 quote: {
		 type: 'String',
		 default: null,
		 array: false,
		 min: 2,
		 max: 140,
	 },
};
SettingsCache.add('users', validate, schema);

<async> validate(resolver, guild)

The validator function Klasa uses for guild settings.
Parameters:
Name Type Description
resolver SettingResolver The resolver instance this SettingGateway uses to parse the data.
guild Object | string The data to validate.
Source:
lib/settings/SettingsCache.js#L74
Returns:
Type
any