Class: Collection

Collection(env)

Base class representing a collection of items with various methods to manipulate and retrieve these items.

Constructor

new Collection(env)

Constructs a new Collection instance.

Parameters:
Name Type Description
env Object

The environment context containing configurations and adapters.

Source:

Classes

Collection

Members

adapter

Deprecated:
  • use data_adapter instead (2024-09-14)
Source:

collection_key

Gets or sets the collection name. If a name is set, it overrides the default name.

Source:

data_path

Gets the data path from the environment.

Deprecated:
  • use env.env_data_dir
Source:

item_class_name

Gets the class name of the item type the collection manages.

Source:

item_name

Gets the name of the item type the collection manages, derived from the class name.

Source:

item_type

Gets the constructor of the item type the collection manages.

Source:

keys

Gets the keys of the items in the collection.

Source:

(static) collection_key

Gets the collection name derived from the class name.

Source:

Methods

clear()

Clears all items from the collection.

Source:

create_or_update(data) → {Promise.<CollectionItem>|CollectionItem}

Creates or updates an item in the collection based on the provided data.

Parameters:
Name Type Description
data Object

The data to create or update an item.

Source:
Returns:

The newly created or updated item.

Type
Promise.<CollectionItem> | CollectionItem

delete_item(key)

Deletes an item from the collection based on its key. Does not trigger save or delete from adapter data.

Parameters:
Name Type Description
key String

The key of the item to delete.

Source:

delete_many(keys)

Deletes multiple items from the collection based on their keys.

Parameters:
Name Type Description
keys Array.<String>

The keys of the items to delete.

Source:

filter(filter_opts) → {Array.<CollectionItem>}

Filters the items in the collection based on the provided options.

Parameters:
Name Type Description
filter_opts Object

The options used to filter the items.

Source:
Returns:

The filtered items.

Type
Array.<CollectionItem>

find_by(data) → {CollectionItem|null}

Finds an item in the collection that matches the given data.

Parameters:
Name Type Description
data Object

The criteria used to find the item.

Source:
Returns:

The found item or null if not found.

Type
CollectionItem | null

get(key) → {CollectionItem}

Retrieves a single item from the collection based on the provided strategy and options.

Parameters:
Name Type Description
key String

The key of the item to retrieve.

Source:
Returns:

The retrieved item.

Type
CollectionItem

get_many(keys) → {Array.<CollectionItem>}

Retrieves multiple items from the collection based on the provided keys.

Parameters:
Name Type Description
keys Array.<String>

The keys of the items to retrieve.

Source:
Returns:

The retrieved items.

Type
Array.<CollectionItem>

get_rand(opts) → {CollectionItem}

Retrieves a random item from the collection based on the provided options.

Parameters:
Name Type Default Description
opts Object null

The options used to retrieve the item.

Source:
Returns:

The retrieved item.

Type
CollectionItem

merge_defaults()

Merges default configurations from all classes in the inheritance chain for Collection types; e.g. EntityCollection, NoteCollection, etc.

Source:

prepare_filter(filter_opts) → {Object}

Prepares filter options for use in the filter implementation. Used by sub-classes to convert simplified filter options into filter_opts compatible with the filter implementation.

Parameters:
Name Type Description
filter_opts Object

The original filter options provided.

Source:
Returns:

The prepared filter options compatible with the filter implementation.

Type
Object

(async) render_settings(container, opts)

Renders the settings for the collection.

Parameters:
Name Type Description
container HTMLElement

The container element to render the settings into.

opts Object

Additional options for rendering.

Properties
Name Type Description
settings_keys Object

An array of keys to render.

Source:

(async) save()

Saves the current state of the collection.

Source:

set(item)

Adds or updates an item in the collection.

Parameters:
Name Type Description
item CollectionItem

The item to add or update.

Source:

update_many(keys, data)

Updates multiple items in the collection based on the provided keys and data.

Parameters:
Name Type Description
keys Array.<String>

The keys of the items to update.

data Object

The data to update the items with.

Source: