npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

y-fdp-storage

v0.2.13

Published

fdp-storage database provider for Yjs

Downloads

10

Readme

y-fdp-storage

fdp-storage database provider for Yjs

Abstract

This Yjs provider uses Swarm Feeds Sequential mechanism, which is more efficient than Swarm Feeds Epoch. This library contains a complete Typescript implementation from scratch.

We also added research technology from previous samples, in this case a simple wrapper which stores/read from a sequential feed. This can be extended to use Beeson, which in this Yjs provider we removed to avoid dependency complexity. Thus, the Yjs update data are stored as hex in the feed.

Because a Swarm Feed requires a Topic and Address, we need to provider a signing private key.

Further enhancements

  • Enable WebSockets for Feeds either in a standalone server or in Swarm, this to avoid doing long-polling.
  • Enable the provider to have a read (public key) and write (signing key) features.

Table of Contents

Install

npm install y-fdp-storage

Usage

import * as Y from 'yjs'
import { Bee } from '@ethersphere/bee-js'
import { hexToBytes, makePrivateKeySigner, FdpStoragePersistence } from 'y-fdp-storage'

const postageBatchId = process.env.BEE_POSTAGE || '1c082c5e642e15d49b6689f5437c2eb9e6aa9c546a8ed1d11d0024b043bca371'
const bee = new Bee('http://localhost:1633')

const testIdentity = {
  privateKey: '634fb5a872396d9693e5c9f9d7233cfa93f395c093371017ff44aa9ae6564cdd',
  publicKey: '03c32bb011339667a487b6c1c35061f15f7edc36aa9a0f8648aba07a4b8bd741b4',
  address: '8d3766440f0d7b949a5e32995d09619a7f86e632',
}
const wallet = makePrivateKeySigner(hexToBytes(testIdentity.privateKey))
const topic = '/crdt/document/test'

// Create FdpStoragePersistence object
const persistence = new FdpStoragePersistence(bee, wallet, topic, postageBatchId)

// Create Yjs document
const doc = new Y.Doc()

// On update event, store updates to bee
doc.on('update', async update => {
    await persistence.storeUpdate(update)
})

// Or use persistence.autoUpdate(doc, interval_milliseconds)

doc.getText('test').insert(0, 'Hello World')

const mostRecentDoc = await persistence.getYDoc()
// Hello World

const close = persistence.subscribe(doc);

Usage with fdp-storage

import * as Y from 'yjs'
import { FdpStorage } from '@fairdatasociety/fdp-storage'
const { hexToBytes } = Utils
import { hexToBytes, makePrivateKeySigner, FdpStoragePersistence } from 'y-fdp-storage'

const postageBatchId = process.env.BEE_POSTAGE || '1c082c5e642e15d49b6689f5437c2eb9e6aa9c546a8ed1d11d0024b043bca371'
const fdp = new FdpStorage('http://localhost:1633', postageBatchId)

const topic = '/crdt/document/test'

// Create FdpStoragePersistence object
const persistence = new FdpStoragePersistence(fdp.connection.bee, fdp.account.wallet, topic, fdp.connection.postageBatchId)

// Create Yjs document
const doc = new Y.Doc()

// On update event, store updates to bee
doc.on('update', async update => {
    await persistence.storeUpdate(update)
})

doc.getText('test').insert(0, 'Hello World')

const mostRecentDoc = await persistence.getYDoc()
// Hello World

API

FdpStoragePersistence

Creates a FdpStoragePersistence instance.

const persistence = new FdpStoragePersistence(fdp.connection.bee, fdp.account.wallet, topic, fdp.connection.postageBatchId)

storeUpdate

Writes the Yjs update to a feed. Handles any throws internally.

const update = Y.encodeStateAsUpdate(doc)
await persistence.storeUpdate(update)

store

Writes the Yjs update to a feed. Errors will be thrown if the update is not valid.

const update = Y.encodeStateAsUpdate(doc)
await persistence.store(update)

read

Reads the latest update from feed.

const update = await persistence.read()

getYDoc

Reads the last state as a YDoc.

const doc = await persistence.getYDoc()

subscribe

Subscribes to the feed and emits updates. Returns a function to cancel subscription interval.

const close = persistence.subscribe(doc, 30_000)

autoUpdate

Pushes updates. Returns a function to cancel push interval.

const close = persistence.autoUpdate(doc, 30_000)

Maintainers

molekilla

References

Yjs

License

Apache License 2.0