Socket
Book a DemoInstallSign in
Socket

passive-core-watcher

Package Overview
Dependencies
Maintainers
0
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

passive-core-watcher

Run conditional logic on a corestore's hypercores

latest
Source
npmnpm
Version
1.0.1
Version published
Maintainers
0
Created
Source

Passive Core Watcher

Run conditional logic on a corestore's hypercores when they open. Useful for example when one hypercore being active implies other hypercores should be active too.

npm i passive-core-watcher

API

const watcher = new PassiveCoreWatcher(corestore, { watch, open })

Create a new passive core watcher, and start watching new cores. Existing cores are also processed (e.g. open will be called for all existing cores for which watch returns true).

corestore is a Corestore

watch is a (possibly async) function, returning a boolean for a given Hypercore.Core object indicating whether the Hypercore should be watched.

open is a (possibly async) function containing the intended side effects for Hypercores which should be watched. Its input is a Hypercore session. It is a weak session, closing when no other sessions exist.

The session emits a close event when it is closing. If teardown of the side effects is needed, a listener needs to be defined in the open function:

session.on('close', () => { /* run teardown logic for side effects */ } )

watcher.destroy()

Stops watching the corestore for new cores, and closes all weak sessions.

await watcher.ensureTracked(key)

key is a hypercore key (buffer, z32 or hex format).

If the hypercore is open in the corestore, it is added to the watcher lifecycle, and the open method is called (does nothing otherwise).

Useful when the watch condition might be false when the core first opens, but became true later.

watcher.on('oncoreopen-error', e)

Emitted when an error is thrown while a new core is being processed (for example during the passed-in watch or open functions). Useful for debugging and logging.

e is an error object.

Keywords

Corestore

FAQs

Package last updated on 12 Mar 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts