0.1.50 • Published 10 months ago

@dxos/feed-store v0.1.50

Weekly downloads
-
License
MIT
Repository
-
Last release
10 months ago

FeedStore

A consistent store for your hypercore feeds.

Build Status Coverage Status npm (scoped) Greenkeeper badge js-semistandard-style standard-readme compliant

FeedStore was created to administrate your hypercore feeds in a similar abstraction to work with files in a FileSystem.

Each feed created by FeedStore works with an underlying object descriptor which provides additional information about the feed and how to work with it.

Features:

  • Open/Close hypercore feeds.
  • Load hypercore feeds by demand.
  • Persist feeds metadata into a hypertrie database.
  • Search feeds by a path or any property related to the feed.
  • Add metadata to your feed.
  • Support for multiple codecs.

Install

$ npm install @dxos/feed-store

Usage

import { FeedStore } from '@dxos/feed-store';

(async () => {
  const feedStore = await FeedStore.create('./db', {
    feedOptions: { valueEncoding: 'utf-8' }
  });

  // Open a feed. If the feed doesn't exist, it would be created.
  const foo = await feedStore.openFeed('/foo');

  foo.append('foo', () => {
    foo.head(console.log);
  });

  // You can open a feed with custom hypercore options.
  const bar = await feedStore.openFeed('/bar', {
    key: Buffer.from('...'),
    secretKey: Buffer.from('...'),
    valueEncoding: 'json',
    metadata: { tag: 'bar' } // Save serializable feed metadata.
  });
})();

API

const feedStore = await feedStore.create(storage, [options])

Creates and initializes a new FeedStore.

  • storage: RandomAccessStorage: Storage used by the feeds to store their data.
  • options:
    • database: Hypertrie: Defines a custom hypertrie database to index the feeds.
    • feedOptions: Object: Default hypercore options for each feed.
    • codecs: Object: Defines a list of available codecs to work with the feeds.
    • timeout: number: Defines the time (ms) to wait for open or close a feed. Default: 10 * 1000.
    • hypercore: Hypercore: Defines the Hypercore class to create feeds.

const feedStore = new FeedStore(storage, [options])

Creates a new FeedStore without wait for their initialization.

The initialization happens by running: await feedStore.initialize()

feedStore.openFeed(path, [options]) -> Promise<Hypercore>

Creates a new hypercore feed identified by a string path.

If the feed exists but is not loaded it will load the feed instead of creating a new one.

  • path: string: A require name to identify and index the feed to open.
  • options: Object: Feed options.
    • metadata: *: Serializable value with custom data about the feed.
    • [...hypercoreOptions]: Hypercore options.

feedStore.closeFeed(path) -> Promise

Close a feed by the path.

feedStore.deleteDescriptor(path) -> Promise

Remove a descriptor from the database by the path.

This operation would not close the feed.

feedStore.close() -> Promise

Close the hypertrie database and their feeds.

feedStore.openFeeds((descriptor) => Boolean) -> Promise<Hypercore[]>

Open multiple feeds using a function to filter what feeds you want to load from the database.

const feeds = await feedStore.loadFeeds(descriptor => descriptor.metadata.tag === 'foo')

feedStore.ready() -> Promise

Wait for feedStore to be ready.

FeedDescriptor

For each feed created, FeedStore maintain FeedDescriptor object.

A FeedDescriptor provides the next information:

  • path: string
  • key: Buffer
  • secretKey: Buffer
  • discoveryKey: Buffer
  • feed: (Hypercore|null)
  • opened: Boolean
  • valueEncoding: string|Codec
  • metadata: *

feedStore.getDescriptors() -> FeedDescriptor[]

Returns a list of descriptors.

feedStore.getOpenFeeds([descriptor => Boolean]) -> Hypercore[]

Returns a list of opened hypercore feeds, with optional filter.

  • descriptor: FeedDescriptor

feedStore.getOpenFeed(descriptor => Boolean) -> Hypercore[]

Find an opened feed using a filter callback.

  • descriptor: FeedDescriptor

feedStore.createReadStream(descriptor => (ReadableStream|Boolean)) -> ReadableStream

Creates a ReadableStream from the loaded feeds.

It uses an optional callback function to return the stream for each feed.

NOTE: If the callback returns false it will ignore the feed.

  • descriptor: FeedDescriptor

Usage:

const stream = feedStore.createReadStream(descriptor => {
  if (descriptor.metadata.tag === 'foo') {
    return descriptor.feed.createReadStream()
  }
})

Events

feedStore.on('ready', () => {})

Emitted when feedStore is loaded.

feedStore.on('append', (feed, descriptor) => {})

Emitted after an append in any of the loaded feeds.

  • feed: Hypercore
  • descriptor: FeedDescriptor

feedStore.on('download', (index, data, feed, descriptor) => {})

Emitted after a feed download event.

  • index: number Block index.
  • data: Buffer
  • feed: Hypercore
  • descriptor: FeedDescriptor

feedStore.on('feed', (feed, descriptor) => {})

Emitted when a feed is loaded.

  • feed: Hypercore
  • descriptor: FeedDescriptor

Contributing

PRs accepted.

License

GPL-3.0 © dxos

0.1.50-main.b2c0d7e

10 months ago

0.1.51-main.6a6c684

10 months ago

0.1.51-main.d153dea

10 months ago

0.1.50-main.88a1229

10 months ago

0.1.50-main.24fefc9

10 months ago

0.1.51-main.cb60375

10 months ago

0.1.51-main.c8526c2

10 months ago

0.1.50-main.c18917d

10 months ago

0.1.50-next.88a1229

10 months ago

0.1.50-main.e80fdfc

10 months ago

0.1.51-main.b72af36

10 months ago

0.1.51-main.d71fd8c

10 months ago

0.1.51-main.d63f207

10 months ago

0.1.51-main.b267b99

10 months ago

0.1.51-main.e7215ae

10 months ago

0.1.50

10 months ago

0.1.51-main.23e9d5d

10 months ago

0.1.51-main.49677b6

10 months ago

0.1.51-main.2c48332

10 months ago

0.1.50-main.3962d45

10 months ago

0.1.50-main.29523e1

10 months ago

0.1.51-main.0ebb085

10 months ago

0.1.51-main.24977a9

10 months ago

0.1.51-main.e27c9c6

10 months ago

0.1.50-main.bc31057

10 months ago

0.1.45-next.45667d4

11 months ago

0.1.50-next.30ca3c7

10 months ago

0.1.50-next.3d8b7c4

10 months ago

0.1.46-next.01810f0

11 months ago

0.1.48-next.806c124

10 months ago

0.1.48-next.83f55fd

11 months ago

0.1.45-next.599f154

11 months ago

0.1.48-next.4b7ebc3

11 months ago

0.1.49

10 months ago

0.1.41

12 months ago

0.1.45

11 months ago

0.1.46

11 months ago

0.1.47

11 months ago

0.1.48

10 months ago

0.1.40

1 year ago

0.1.38

1 year ago

0.1.39

1 year ago

0.1.30

1 year ago

0.1.31

1 year ago

0.1.32

1 year ago

0.1.33

1 year ago

0.1.34

1 year ago

0.1.35

1 year ago

0.1.36

1 year ago

0.1.37

1 year ago

0.1.27

1 year ago

0.1.28

1 year ago

0.1.29

1 year ago

0.1.24

1 year ago

0.1.25

1 year ago

0.1.26

1 year ago

0.1.49-next.f1412c7

10 months ago

0.1.46-next.412561

11 months ago

0.1.49-next.55d8a92

10 months ago

0.1.50-main.cab6083

10 months ago

0.1.50-next.1bfebf8

10 months ago

0.1.49-next.7ec9d52

10 months ago

0.1.49-next.c888fc1

10 months ago

0.1.42-next.6e229fb

12 months ago

0.1.48-next.366bc83

11 months ago

0.1.41-next.e3d5f34

12 months ago

0.1.46-next.c3cc04c

11 months ago

0.1.49-next.fdd6c88

10 months ago

0.1.50-next.53f1631

10 months ago

0.1.14

1 year ago

0.1.20

1 year ago

0.1.21

1 year ago

0.1.22

1 year ago

0.1.23

1 year ago

0.1.16

1 year ago

0.1.17

1 year ago

0.1.18

1 year ago

0.1.19

1 year ago

0.1.10

1 year ago

0.1.11

1 year ago

0.1.12

1 year ago

0.1.13

1 year ago

0.1.0

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.8

1 year ago

0.1.7

1 year ago

0.1.9

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.6

1 year ago

0.1.5

1 year ago

2.33.1

2 years ago

2.33.0

2 years ago

2.33.7

2 years ago

2.33.6

2 years ago

2.33.8

2 years ago

2.33.3

2 years ago

2.33.2

2 years ago

2.33.5

2 years ago

2.33.4

2 years ago

2.32.0

2 years ago

2.31.1

2 years ago

2.31.0

2 years ago

2.31.3

2 years ago

2.31.2

2 years ago

2.31.5

2 years ago

2.31.4

2 years ago

2.31.7

2 years ago

2.31.6

2 years ago

2.30.2

2 years ago

2.30.1

2 years ago

2.30.0

2 years ago

2.29.0

2 years ago

2.29.1

2 years ago

2.28.22

2 years ago

2.28.23

2 years ago

2.28.20

2 years ago

2.28.21

2 years ago

2.28.19

2 years ago

2.28.17

2 years ago

2.28.18

2 years ago

2.28.15

2 years ago

2.28.16

2 years ago

2.28.9

2 years ago

2.28.8

2 years ago

2.28.5

2 years ago

2.28.4

2 years ago

2.28.7

2 years ago

2.28.6

2 years ago

2.28.13

2 years ago

2.28.14

2 years ago

2.28.11

2 years ago

2.28.12

2 years ago

2.28.10

2 years ago

2.22.0

2 years ago

2.21.0

2 years ago

2.21.2

2 years ago

2.21.1

2 years ago

2.20.0

2 years ago

2.19.8

2 years ago

2.19.9

2 years ago

2.19.6

2 years ago

2.19.7

2 years ago

2.19.4

2 years ago

2.19.5

2 years ago

2.19.3

2 years ago

2.28.1

2 years ago

2.28.0

2 years ago

2.28.3

2 years ago

2.28.2

2 years ago

2.27.9

2 years ago

2.27.6

2 years ago

2.27.5

2 years ago

2.27.8

2 years ago

2.27.7

2 years ago

2.27.2

2 years ago

2.27.1

2 years ago

2.27.4

2 years ago

2.27.3

2 years ago

2.27.0

2 years ago

2.26.1

2 years ago

2.26.0

2 years ago

2.19.10

2 years ago

2.19.11

2 years ago

2.25.0

2 years ago

2.24.0

2 years ago

2.23.0

2 years ago

2.19.2

2 years ago

2.19.0

2 years ago

2.19.1

2 years ago

2.18.3

2 years ago

2.18.2

2 years ago

2.18.1

2 years ago

2.18.0

2 years ago

2.16.15

2 years ago

2.16.14

2 years ago

2.16.17

2 years ago

2.16.16

2 years ago

2.16.11

2 years ago

2.16.10

2 years ago

2.16.13

2 years ago

2.16.12

2 years ago

2.17.4

2 years ago

2.17.2

2 years ago

2.17.3

2 years ago

2.17.0

2 years ago

2.17.1

2 years ago

2.16.9

2 years ago

2.16.7

2 years ago

2.16.8

2 years ago

2.16.6

2 years ago

2.16.5

2 years ago

2.16.3

2 years ago

2.16.4

2 years ago

2.15.8

3 years ago

2.15.9

3 years ago

2.15.6

3 years ago

2.15.7

3 years ago

2.15.4

3 years ago

2.15.5

3 years ago

2.15.2

3 years ago

2.15.3

3 years ago

2.15.0

3 years ago

2.15.1

3 years ago

2.14.5

3 years ago

2.16.1

3 years ago

2.16.2

2 years ago

2.16.0

3 years ago

2.14.3

3 years ago

2.14.4

3 years ago

2.14.1

3 years ago

2.14.2

3 years ago

2.13.0

3 years ago

2.14.0

3 years ago

2.12.23

3 years ago

2.12.22

3 years ago

2.12.21

3 years ago

2.12.20

3 years ago

2.12.19

3 years ago

2.12.18

3 years ago

2.12.17

3 years ago

2.11.0

3 years ago

2.11.1

3 years ago

2.10.1-beta.4

3 years ago

2.12.0

3 years ago

2.10.10

3 years ago

2.10.11

3 years ago

2.10.12

3 years ago

2.10.13

3 years ago

2.10.14

3 years ago

2.10.15

3 years ago

2.10.16

3 years ago

2.10.17

3 years ago

2.12.9

3 years ago

2.12.7

3 years ago

2.10.9

3 years ago

2.12.16

3 years ago

2.12.8

3 years ago

2.12.15

3 years ago

2.12.5

3 years ago

2.10.7

3 years ago

2.12.14

3 years ago

2.12.6

3 years ago

2.10.8

3 years ago

2.12.13

3 years ago

2.12.3

3 years ago

2.12.12

3 years ago

2.12.4

3 years ago

2.10.6

3 years ago

2.12.11

3 years ago

2.12.1

3 years ago

2.12.10

3 years ago

2.12.2

3 years ago

1.2.0-beta.30

4 years ago

1.2.0-beta.29

4 years ago

1.2.0-beta.28

4 years ago

1.2.0-beta.27

4 years ago

1.2.0-beta.26

4 years ago

1.2.0-beta.25

4 years ago

1.2.0-beta.24

4 years ago

1.2.0-beta.23

4 years ago

1.2.0-beta.22

4 years ago

1.2.0-beta.21

4 years ago

1.2.0-beta.20

4 years ago

1.2.0-beta.19

4 years ago

1.2.0-beta.18

4 years ago

1.2.0-beta.17

4 years ago

1.2.0-beta.16

4 years ago

1.2.0-beta.15

4 years ago

1.2.0-beta.14

4 years ago

1.2.0-beta.13

4 years ago

1.2.0-beta.12

4 years ago

1.2.0-beta.11

4 years ago

1.2.0-beta.10

4 years ago

1.2.0-beta.9

4 years ago

1.2.0-beta.8

4 years ago

1.2.0-beta.7

4 years ago

1.2.0-beta.6

4 years ago

1.2.0-beta.5

4 years ago

1.2.0-beta.4

4 years ago

1.2.0-beta.3

4 years ago

1.2.0-beta.2

4 years ago

1.2.0-beta.1

4 years ago

1.2.0-beta.0

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago