Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Settings

Hierarchy

  • Cache<string, unknown>
    • Settings

Index

Constructors

constructor

Properties

existenceStatus

existenceStatus: SettingsExistenceStatus

The existence status of this entry.

internal

Readonly gateway

gateway: Gateway

The gateway that manages this instance.

Readonly id

id: string

The ID of the database entry this instance manages.

Readonly size

size: number

Readonly target

target: unknown

The holder of this instance.

Accessors

client

first

  • get first(): [string, unknown] | null
  • The first item in this Cache

    Returns [string, unknown] | null

firstKey

  • get firstKey(): string | null
  • The first key of this cache

    Returns string | null

firstValue

  • get firstValue(): unknown | null
  • The first value of this cache

    Returns unknown | null

last

  • get last(): [string, unknown] | null
  • The last item in this cache

    Returns [string, unknown] | null

lastKey

  • get lastKey(): string | null
  • The last key of this cache

    Returns string | null

lastValue

  • get lastValue(): unknown | null
  • The last value of this cache

    Returns unknown | null

Methods

Protected _init

  • _init(): void

Protected _patch

  • _patch(data: unknown): void

Private _processUpdate

Private _resetSettingsEntry

Private _resolveEntry

Private _resolveNextValue

Private _resolveValues

Protected _save

Private _updateSchemaEntryValue

Private _updateSettingsEntry

Private _updateSettingsEntryAtIndex

  • _updateSettingsEntryAtIndex(previous: keyof unknown[], values: keyof unknown[], arrayIndex: number, arrayAction: ArrayActions | null): unknown[]

Private _updateSettingsEntryNotIndexed

clear

  • clear(): void
  • Returns void

clone

concat

  • concat(...caches: Cache<string, unknown>[]): Cache<string, unknown>
  • Returns a new Cache with this and other caches together

    Parameters

    • Rest ...caches: Cache<string, unknown>[]

      Other caches to include in the new cache

    Returns Cache<string, unknown>

delete

  • delete(key: string): boolean
  • Parameters

    • key: string

    Returns boolean

destroy

  • destroy(): Promise<this>

equals

  • equals(cache: Cache<string, unknown>): boolean
  • Naive equality compare function

    Parameters

    • cache: Cache<string, unknown>

      The cache to compare this against

    Returns boolean

every

  • every(fn: (value: unknown, key: string, map: this) => boolean, thisArg?: any): boolean
  • Tests if every entry in this cache meets a condition

    Parameters

    • fn: (value: unknown, key: string, map: this) => boolean

      The function to test the condition

        • (value: unknown, key: string, map: this): boolean
        • Parameters

          • value: unknown
          • key: string
          • map: this

          Returns boolean

    • Optional thisArg: any

      Optional binding for the fn param

    Returns boolean

filter

  • filter(fn: (value: unknown, key: string, map: this) => boolean, thisArg?: any): Cache<string, unknown>
  • Returns a new filtered Cache based on the filter function

    Parameters

    • fn: (value: unknown, key: string, map: this) => boolean

      Function used to determine what entries are in the new Cache

        • (value: unknown, key: string, map: this): boolean
        • Parameters

          • value: unknown
          • key: string
          • map: this

          Returns boolean

    • Optional thisArg: any

      Optional binding for the fn param

    Returns Cache<string, unknown>

find

  • find(fn: (value: unknown, key: string, map: this) => boolean, thisArg?: any): [string, unknown] | undefined
  • Finds an entry from this Cache

    Parameters

    • fn: (value: unknown, key: string, map: this) => boolean

      Function used to find what you are looking for

        • (value: unknown, key: string, map: this): boolean
        • Parameters

          • value: unknown
          • key: string
          • map: this

          Returns boolean

    • Optional thisArg: any

      Optional binding for the fn param

    Returns [string, unknown] | undefined

findKey

  • findKey(fn: (value: unknown, key: string, map: this) => boolean, thisArg?: any): string | undefined
  • Finds a key from this Cache

    Parameters

    • fn: (value: unknown, key: string, map: this) => boolean

      Function used to find what you are looking for

        • (value: unknown, key: string, map: this): boolean
        • Parameters

          • value: unknown
          • key: string
          • map: this

          Returns boolean

    • Optional thisArg: any

      Optional binding for the fn param

    Returns string | undefined

findValue

  • findValue(fn: (value: unknown, key: string, map: this) => boolean, thisArg?: any): unknown | undefined
  • Finds a value from this Cache

    Parameters

    • fn: (value: unknown, key: string, map: this) => boolean

      Function used to find what you are looking for

        • (value: unknown, key: string, map: this): boolean
        • Parameters

          • value: unknown
          • key: string
          • map: this

          Returns boolean

    • Optional thisArg: any

      Optional binding for the fn param

    Returns unknown | undefined

forEach

  • forEach(callbackfn: (value: unknown, key: string, map: Map<string, unknown>) => void, thisArg?: any): void
  • Parameters

    • callbackfn: (value: unknown, key: string, map: Map<string, unknown>) => void
        • (value: unknown, key: string, map: Map<string, unknown>): void
        • Parameters

          • value: unknown
          • key: string
          • map: Map<string, unknown>

          Returns void

    • Optional thisArg: any

    Returns void

get

  • get(key: string): unknown | undefined
  • Parameters

    • key: string

    Returns unknown | undefined

has

  • has(key: string): boolean
  • Parameters

    • key: string

    Returns boolean

map

  • map<T>(fn: (value: unknown, key: string, map: this) => T, thisArg?: any): T[]
  • Maps this Cache to an array (like Array#map())

    Type parameters

    • T

    Parameters

    • fn: (value: unknown, key: string, map: this) => T

      Function to determine what is mapped to the new Array

        • (value: unknown, key: string, map: this): T
        • Parameters

          • value: unknown
          • key: string
          • map: this

          Returns T

    • Optional thisArg: any

      Optional binding for the fn param

    Returns T[]

pluck

  • pluck(...paths: keyof string[]): unknown[]
  • Plucks out one or more attributes from either an object or a sequence of objects

    example

    const [x, y] = message.guild.settings.pluck('x', 'y'); console.log(x, y);

    Parameters

    • Rest ...paths: keyof string[]

      The paths to take

    Returns unknown[]

reduce

  • reduce<I>(fn: (accumulator: I, value: unknown, key: string, map: this) => I, initialValue: I, thisArg?: any): I
  • Reduces this cache into a singularity

    Type parameters

    • I

    Parameters

    • fn: (accumulator: I, value: unknown, key: string, map: this) => I

      The function to determine how this Cache is reduced

        • (accumulator: I, value: unknown, key: string, map: this): I
        • Parameters

          • accumulator: I
          • value: unknown
          • key: string
          • map: this

          Returns I

    • initialValue: I

      The initial value

    • Optional thisArg: any

      Optional binding for the fn param

    Returns I

reset

  • Resets all keys from the instance.

    example

    // Resets all entries: await message.guild.settings.reset();

    Returns Promise<SettingsUpdateResults>

  • Resets a key from the instance.

    example

    // Resets an entry: await message.guild.settings.reset('prefix');

    Parameters

    • path: string

      The path of the key to reset from the instance

    • Optional options: Readonly<SettingsResetOptions>

      The options for this action

    Returns Promise<SettingsUpdateResults>

  • Resets multiple keys from the instance.

    example

    // Resets an entry: await message.guild.settings.reset(['prefix']);

    example

    // Resets multiple entries: await message.guild.settings.reset(['prefix', 'administrator']);

    Parameters

    • paths: keyof string[]

      The paths of the keys to reset from the instance

    • Optional options: Readonly<SettingsResetOptions>

      The options for this action

    Returns Promise<SettingsUpdateResults>

  • Resets multiple keys from the instance.

    example

    // Resets an entry: await message.guild.settings.reset({ prefix: null });

    example

    // Resets multiple entries with a regular object: await message.guild.settings.reset({ prefix: null, administrator: null });

    Parameters

    Returns Promise<SettingsUpdateResults>

resolve

  • resolve(...paths: keyof string[]): Promise<unknown[]>
  • Resolves paths into their full objects or values depending on the current set value

    Parameters

    • Rest ...paths: keyof string[]

      The paths to resolve

    Returns Promise<unknown[]>

set

  • set(key: string, value: unknown): this
  • Parameters

    • key: string
    • value: unknown

    Returns this

some

  • some(fn: (value: unknown, key: string, map: this) => boolean, thisArg?: any): boolean
  • Tests if some entries in this cache meets a condition

    Parameters

    • fn: (value: unknown, key: string, map: this) => boolean

      The function to test the condition

        • (value: unknown, key: string, map: this): boolean
        • Parameters

          • value: unknown
          • key: string
          • map: this

          Returns boolean

    • Optional thisArg: any

      Optional binding for the fn param

    Returns boolean

sort

  • sort(compareFunction?: undefined | ((v0: unknown, v1: unknown, k0?: K, k1?: K) => number)): this
  • Sorts entries in-place in this Cache

    Parameters

    • Optional compareFunction: undefined | ((v0: unknown, v1: unknown, k0?: K, k1?: K) => number)

      Function to determine how this Cache should be sorted

    Returns this

sorted

  • sorted(compareFunction?: undefined | ((v0: unknown, v1: unknown, k0?: K, k1?: K) => number)): Cache<string, unknown>
  • Sorts entries in a new Cache

    Parameters

    • Optional compareFunction: undefined | ((v0: unknown, v1: unknown, k0?: K, k1?: K) => number)

      Function to determine how the resulting Cache should be sorted

    Returns Cache<string, unknown>

sweep

  • sweep(fn: (value: unknown, key: string, map: this) => boolean, thisArg?: any): number
  • Sweeps entries from this Cache

    Parameters

    • fn: (value: unknown, key: string, map: this) => boolean

      Function used to determine what entries are swept

        • (value: unknown, key: string, map: this): boolean
        • Parameters

          • value: unknown
          • key: string
          • map: this

          Returns boolean

    • Optional thisArg: any

      Optional binding for the fn param

    Returns number

sync

  • sync(force?: boolean): Promise<this>
  • Sync the data from the database with the cache.

    Parameters

    • Default value force: boolean = this.existenceStatus === SettingsExistenceStatus.Unsynchronized

      Whether or not this should force a database synchronization

    Returns Promise<this>

toJSON

update

  • Update a key from the instance.

    example

    // Change the prefix to '$': await message.guild.settings.update('prefix', '$');

    example

    // Add a new value to an array await message.guild.settings.update('disabledCommands', 'ping', { arrayAction: 'add' });

    example

    // Remove a value from an array await message.guild.settings.update('disabledCommands', 'ping', { arrayAction: 'remove' });

    example

    // Remove a value from an array of tuples ([[k1, v1], [k2, v2], ...]) const tags = message.guild.settings.get('tags'); const index = tags.findIndex(([tag]) => tag === 'foo'); await message.guild.settings.update('tags', null, { arrayIndex: index });

    Parameters

    • path: string

      The path of the key to update

    • value: unknown

      The new value to validate and set

    • Optional options: SettingsUpdateOptions

      The options for this update

    Returns Promise<SettingsUpdateResults>

  • Update one or more keys from the instance.

    example

    // Change the prefix to '$' and update disabledCommands adding/removing 'ping': await message.guild.settings.update([['prefix', '$'], ['disabledCommands', 'ping']]);

    example

    // Add a new value to an array await message.guild.settings.update([['disabledCommands', 'ping']], { arrayAction: 'add' });

    example

    // Remove a value from an array await message.guild.settings.update([['disabledCommands', 'ping']], { arrayAction: 'remove' });

    example

    // Remove a value from an array of tuples ([[k1, v1], [k2, v2], ...]) const tags = message.guild.settings.get('tags'); const index = tags.findIndex(([tag]) => tag === 'foo'); await message.guild.settings.update([['tags', null]], { arrayIndex: index });

    Parameters

    • entries: [string, unknown][]

      The key and value pairs to update

    • Optional options: SettingsUpdateOptions

      The options for this update

    Returns Promise<SettingsUpdateResults>

  • Update one or more keys using an object approach.

    example

    // Change the prefix to '$' and update disabledCommands adding/removing 'ping': await message.guild.settings.update({ prefix: '$', disabledCommands: 'ping' });

    example

    // Add a new value to an array await message.guild.settings.update({ disabledCommands: ['ping'] }, { arrayAction: 'add' });

    example

    // Remove a value from an array await message.guild.settings.update({ disabledCommands: ['ping'] }, { arrayAction: 'remove' });

    example

    // Remove a value from an array of tuples ([[k1, v1], [k2, v2], ...]) const tags = message.guild.settings.get('tags'); const index = tags.findIndex(([tag]) => tag === 'foo'); await message.guild.settings.update({ tags: null }, { arrayIndex: index });

    Parameters

    Returns Promise<SettingsUpdateResults>

Generated using TypeDoc