Collection

Collection

Represents a Firestorm Collection

Constructor

new Collection(name, addMethodsopt)

Description:
  • Create a new Firestorm collection instance

Source:
Parameters:
Name Type Attributes Description
name string

The name of the collection

addMethods function <optional>

Additional methods and data to add to the objects

Methods

add(value) → {Promise.<string>}

Description:
  • Append a value to the collection

    • Only works if autoKey is enabled server-side
Source:
Parameters:
Name Type Description
value T

The value (without methods) to add

Returns:

The generated key of the added element

Type
Promise.<string>

addBulk(values) → {Promise.<Array.<string>>}

Description:
  • Append multiple values to the collection

    • Only works if autoKey is enabled server-side
Source:
Parameters:
Name Type Description
values Array.<T>

The values (without methods) to add

Returns:

The generated keys of the added elements

Type
Promise.<Array.<string>>

editField(option) → {Promise.<WriteConfirmation>}

Description:
  • Edit an element's field in the collection

Source:
Parameters:
Name Type Description
option EditFieldOption

The edit object

Returns:

Edit confirmation

Type
Promise.<WriteConfirmation>

editFieldBulk(options) → {Promise.<WriteConfirmation>}

Description:
  • Edit multiple elements' fields in the collection

Source:
Parameters:
Name Type Description
options Array.<EditFieldOption>

The edit objects

Returns:

Edit confirmation

Type
Promise.<WriteConfirmation>

get(key) → {Promise.<T>}

Description:
  • Get an element from the collection by its key

Source:
Parameters:
Name Type Description
key string | number

Key to search

Returns:

The found element

Type
Promise.<T>

random(max, seed, offset) → {Promise.<Array.<T>>}

Description:
  • Read random elements of the collection

Source:
Parameters:
Name Type Description
max number

The maximum number of entries

seed number

The seed to use

offset number

The offset to use

Returns:

The found elements

Type
Promise.<Array.<T>>

read_raw() → {Promise.<Record.<string, T>>}

Description:
  • Read the entire collection

    • ID values are injected for easier iteration, so this may be different from sha1
Source:
Deprecated:
  • Use readRaw instead
Returns:

The entire collection

Type
Promise.<Record.<string, T>>

readRaw(originalopt) → {Promise.<Record.<string, T>>}

Description:
  • Read the entire collection

Source:
Parameters:
Name Type Attributes Default Description
original boolean <optional>
false

Disable ID field injection for easier iteration (default false)

Returns:

The entire collection

Type
Promise.<Record.<string, T>>

remove(key) → {Promise.<WriteConfirmation>}

Description:
  • Remove an element from the collection by its key

Source:
Parameters:
Name Type Description
key string | number

The key from the entry to remove

Returns:

Write confirmation

Type
Promise.<WriteConfirmation>

removeBulk(keys) → {Promise.<WriteConfirmation>}

Description:
  • Remove multiple elements from the collection by their keys

Source:
Parameters:
Name Type Description
keys Array.<string> | Array.<number>

The key from the entries to remove

Returns:

Write confirmation

Type
Promise.<WriteConfirmation>
Description:
  • Search through the collection

Source:
Parameters:
Name Type Attributes Default Description
options Array.<SearchOption>

Array of search options

random boolean | number <optional>
false

Random result seed, disabled by default, but can activated with true or a given seed

Returns:

The found elements

Type
Promise.<Array.<T>>

searchKeys(keys) → {Promise.<Array.<T>>}

Description:
  • Get multiple elements from the collection by their keys

Source:
Parameters:
Name Type Description
keys Array.<string> | Array.<number>

Array of keys to search

Returns:

The found elements

Type
Promise.<Array.<T>>

select(option) → {Promise.<Record.<string, Partial.<T>>>}

Description:
  • Get only selected fields from the collection

    • Essentially an upgraded version of readRaw
Source:
Parameters:
Name Type Description
option SelectOption

The fields you want to select

Returns:

Selected fields

Type
Promise.<Record.<string, Partial.<T>>>

set(key, value) → {Promise.<WriteConfirmation>}

Description:
  • Set a value in the collection by key

Source:
Parameters:
Name Type Description
key string

The key of the element you want to edit

value T

The value (without methods) you want to edit

Returns:

Write confirmation

Type
Promise.<WriteConfirmation>

setBulk(keys, values) → {Promise.<WriteConfirmation>}

Description:
  • Set multiple values in the collection by their keys

Source:
Parameters:
Name Type Description
keys Array.<string>

The keys of the elements you want to edit

values Array.<T>

The values (without methods) you want to edit

Returns:

Write confirmation

Type
Promise.<WriteConfirmation>

sha1() → {string}

Description:
  • Get the sha1 hash of the JSON

    • Can be used to compare file content without downloading the file
Source:
Returns:

The sha1 hash of the file

Type
string

values(option) → {Promise.<Array.<T>>}

Description:
  • Get all distinct non-null values for a given key across a collection

Source:
Parameters:
Name Type Description
option ValueOption

Value options

Returns:

Array of unique values

Type
Promise.<Array.<T>>

write_raw(value) → {Promise.<WriteConfirmation>}

Description:
  • Set the entire content of the collection.

    • Only use this method if you know what you are doing!
Source:
Deprecated:
  • Use writeRaw instead
Parameters:
Name Type Description
value Record.<string, T>

The value to write

Returns:

Write confirmation

Type
Promise.<WriteConfirmation>

writeRaw(value) → {Promise.<WriteConfirmation>}

Description:
  • Set the entire content of the collection.

    • Only use this method if you know what you are doing!
Source:
Parameters:
Name Type Description
value Record.<string, T>

The value to write

Returns:

Write confirmation

Type
Promise.<WriteConfirmation>