Class: FilterStorage

filterStorage~FilterStorage

filterStorage implementation.

Members

(private) _knownSubscriptions :Map.<string, module:subscriptionClasses.Subscription>

Map of subscriptions already on the list, by their URL/identifier.

Type:
Source:

(private) _metadataSubscriptions :Map.<string, module:subscriptionClasses.Subscription>

Map of subscriptions with metadata, by their URL/identifier.

It can be used to answer "which subscriptions have metadata?".

Type:
Source:

(private) _needsSave :boolean

Will be set to true if a saveToDisk() call arrives while saveToDisk() is already running (delayed execution).

Type:
  • boolean
Source:

(private) _saving :boolean

Will be set to true if saveToDisk() is running (reentrance protection).

Type:
  • boolean
Source:

(private) _stats :Map.<string, Stats>

This property is for testing purpose only and it should never be used directly via code.

Type:
  • Map.<string, Stats>
Source:

fileProperties :Object

Map of properties listed in the filter storage file before the sections start. Right now this should be only the format version.

Type:
  • Object
Source:

firstRun :boolean

Will be set to true if no patterns.ini file exists.

Type:
  • boolean
Source:

formatVersion :number

The version number of the patterns.ini format used.

Type:
  • number
Source:

initialized :boolean

Will be set to true after the initial loadFromDisk() call completes.

Type:
  • boolean
Source:

sourceFile :string

The file containing the subscriptions.

Type:
  • string
Source:

Methods

(async) addFilter(filter, subscriptionopt, nullable, positionopt) → {Promise.<module:subscriptionClasses.SpecialSubscription>}

Adds a user-defined filter to the storage.

Parameters:
Name Type Attributes Description
filter Filter
subscription module:subscriptionClasses.SpecialSubscription <optional>
<nullable>

The subscription that the filter should be added to.

position number <optional>

The position within the subscription at which the filter should be added. If not specified, the filter is added at the end of the subscription.

Source:
Returns:

The subscription the filter is in. Either existing or added.

Type
Promise.<module:subscriptionClasses.SpecialSubscription>

(async) addFiltersWithMetadata(filters, metadata) → {Promise.<module:subscriptionClasses.SpecialSubscription>}

Adds user-defined filters to the storage with metadata.

Parameters:
Name Type Description
filters Filter | Array.<Filter>

Filter(s) to add. If the list contains duplicate entries, they'll be skipped.

metadata Object

The metadata block.

Source:
Returns:

the subscription the filter is in, or throw an error if any of the filter is already present in a SpecialSubscription.

Type
Promise.<module:subscriptionClasses.SpecialSubscription>

addSubscription(subscription)

Adds a subscription to the storage.

Parameters:
Name Type Description
subscription module:subscriptionClasses.Subscription

The subscription to be added.

Source:

(generator) exportData() → {string}

Generator serializing filter data and yielding it line by line.

Source:
Yields:
Type
string

filtersExist(filters) → {Array.<string>}

Check the filters pass and return the list of the filters that exist.

Parameters:
Name Type Description
filters Array.<string>

The filters to check.

Source:
Returns:

The list of filters that exists. An empty list mean that none do exist.

Type
Array.<string>

(async, package) getBackupFiles() → {Promise.<Array.<FileInfo>>}

Returns a promise resolving in a list of existing backup files.

Source:
Returns:
Type
Promise.<Array.<FileInfo>>

(package) getBackupName(backupIndex) → {string}

Constructs the file name for a patterns.ini backup.

Parameters:
Name Type Description
backupIndex number

Number of the backup file (1 being the most recent).

Source:
Returns:

Backup file name.

Type
string

getGroupForFilter(filter) → (nullable) {module:subscriptionClasses.SpecialSubscription}

Finds the filter group that a filter should be added to by default. Will return null if this group doesn't exist yet.

Parameters:
Name Type Description
filter Filter
Source:
Returns:
Type
module:subscriptionClasses.SpecialSubscription

(async) getMetadataForFilter(text) → {Promise.<Object>}

Get the metadata for a filter.

Parameters:
Name Type Description
text string

The filter text.

Source:
Returns:

The metadata if any found.

This function will iterate through all the subscriptions with metadata to find a SpecialSubscription that contains the filter text.

Type
Promise.<Object>

getSubscription(subscription) → {module:subscriptionClasses.Subscription}

Get the the subscription from the storage.

Parameters:
Name Type Description
subscription string

The URL of the subscription.

Source:
Returns:
Type
module:subscriptionClasses.Subscription

getSubscriptionCount(filterTextopt, nullable) → {number}

Returns the number of subscriptions in the storage.

Parameters:
Name Type Attributes Default Description
filterText string <optional>
<nullable>
null

The filter text for which to look. If specified, the function counts only those subscriptions that contain the given filter text. By default the function counts all subscriptions.

Source:
Returns:
Type
number

hasSubscription(subscription) → {boolean}

Checks whether a given subscription is in the storage.

Parameters:
Name Type Description
subscription module:subscriptionClasses.Subscription | string

or the URL of the subscription.

Source:
Returns:
Type
boolean

(package) importData(silent) → {TextSink}

Allows importing previously serialized filter data.

Parameters:
Name Type Description
silent boolean

If true, no "load" notification will be sent out.

Source:
Returns:

The function to be called for each line of data. Calling it with null as the argument finalizes the import and replaces existing data. No changes will be applied before finalization, so import can be "aborted" by forgetting this callback.

Type
TextSink

increaseHitCount(filter)

Increases the hit count for a filter by one.

Parameters:
Name Type Description
filter Filter
Source:

(async, package) loadFromDisk() → {Promise}

Loads all subscriptions from disk.

Source:
Returns:

A promise resolved or rejected when loading is complete.

Type
Promise

moveFilter(filter, subscription, oldPosition, newPosition)

Moves a user-defined filter to a new position.

Parameters:
Name Type Description
filter module:filterClasses.Filter
subscription module:subscriptionClasses.SpecialSubscription

The subscription where the filter is located.

oldPosition number

The current position of the filter.

newPosition number

The new position of the filter.

Source:

removeFilter(filter, subscriptionopt, nullable, positionopt)

Removes a user-defined filter from the storage.

Parameters:
Name Type Attributes Description
filter module:filterClasses.Filter
subscription module:subscriptionClasses.SpecialSubscription <optional>
<nullable>

The subscription that the filter should be removed from. If not specified, the filter will be removed from all subscriptions.

position number <optional>

The position within the subscription at which the filter should be removed. If not specified, all instances of the filter will be removed.

Source:

removeSubscription(subscription)

Removes a subscription from the storage.

Parameters:
Name Type Description
subscription module:subscriptionClasses.Subscription

The subscription to be removed.

Source:

resetHitCounts(filtersopt, nullable)

Resets hit count for some filters.

Parameters:
Name Type Attributes Description
filters Array.<Filter> <optional>
<nullable>

The filters to be reset. If not specified, all filters will be reset.

Source:

(async, package) restoreBackup(backupIndex, silent) → {Promise}

Restores an automatically created backup.

Parameters:
Name Type Description
backupIndex number

Number of the backup to restore (1 being the most recent).

silent boolean

If true, no "load" notification will be sent out.

Source:
Returns:

A promise resolved or rejected when restoration is complete.

Type
Promise

(async, package) saveToDisk() → {Promise}

Saves all subscriptions back to disk.

Source:
Returns:

A promise resolved or rejected when saving is complete.

Type
Promise

(async) setMetadataForFilter(text, metadata) → {Promise.<module:subscriptionClasses.SpecialSubscription>}

Set the metadata for a filter that already has metadata.

A filter can have metadata only if it was added using addFiltersWithMetadata(). It is currently not possible to add metadata to an existing custom filter that was added with addFilter(). In that case, the function will return a filter_not_found error.

Parameters:
Name Type Description
text string

The filter text.

metadata Object

The metadata.

Source:
Returns:

The subscription whose metadata was changed.

Type
Promise.<module:subscriptionClasses.SpecialSubscription>

(generator) subscriptions(filterTextopt, nullable) → {module:subscriptionClasses.Subscription}

Yields subscriptions in the storage.

Parameters:
Name Type Attributes Default Description
filterText string <optional>
<nullable>
null

The filter text for which to look. If specified, the function yields only those subscriptions that contain the given filter text. By default the function yields all subscriptions.

Source:
Yields:
Type
module:subscriptionClasses.Subscription

updateSubscriptionFilters(subscription, filterText)

Replaces the list of filters in a subscription with a new list.

Parameters:
Name Type Description
subscription module:subscriptionClasses.Subscription

The subscription to be updated.

filterText Array.<string>

The new filter text.

Source: