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

@scobru/mogu

v2.2.1

Published

Mogu is a TypeScript-based project that integrates GunDB with IPFS to provide a decentralized and efficient data storage solution. It includes features for real-time updates, backups, and restores via Web3Stash and IPFS.

Downloads

523

Readme

Mogu Project Documentation

Mogu is a TypeScript-based project that integrates GunDB with IPFS to provide a decentralized and efficient data storage solution. It includes features for real-time updates, backups, and restores via Web3Stash and IPFS.

Table of Contents


Introduction

Mogu provides developers with tools to build decentralized and efficient applications using GunDB for data synchronization and IPFS for storage. It supports features like data backup, restore, and real-time updates, making it ideal for decentralized applications (dApps).

Features

  • Real-time data synchronization using GunDB
  • Data backup and restore using IPFS and Web3Stash
  • Supports both local and IPFS-based storage
  • Modular design for easy integration with other services
  • Backup comparison functionality
  • Support for basic CRUD operations
  • Reliable backup and restore system
  • Support for multiple storage providers (Pinata, Web3.Storage, NFT.Storage)
  • Automatic cryptographic key management
  • Integrated caching system
  • Support for structured and unstructured data

Installation

To set up the project locally, follow these steps:

  1. Install the package via npm:

    npm install @scobru/mogu
  2. Create a .env file in the root directory with the following variables:

    PINATA_API_KEY=<your-pinata-api-key>
    PINATA_API_SECRET=<your-pinata-api-secret>
    PINATA_GATEWAY=<your-pinata-gateway>
    DB_NAME=<your-db-name>
    PRIVATE_KEY=<your-private-key>
    PROVIDER_URL=<your-provider-url>
    STORAGE=true
  3. Import and initialize Mogu in your project:

    import { Mogu } from '@scobru/mogu';
       
    const mogu = new Mogu({
      dbName: process.env.DB_NAME,
      storage: process.env.STORAGE === 'true',
      privateKey: process.env.PRIVATE_KEY,
      providerUrl: process.env.PROVIDER_URL
    });

Usage

Mogu SDK

The Mogu SDK provides a comprehensive set of features to interact with the system. Here's the detailed documentation:

Initialization

import { Mogu } from '@scobru/mogu';

const options = {
  key: "optional-key",
  storageService: "pinata", // or other supported services
  storageConfig: {
    // storage service configuration
  },
  server: {}, // optional GunDB server configuration
  useIPFS: true // enable IPFS usage
};

const mogu = new Mogu(options);

Core Methods

getGunInstance()

Returns the GunDB instance.

const gunInstance = mogu.getGunInstance();
get(key: string)

Retrieves data from the specified key.

const data = await mogu.get("myKey");
put(key: string, data: any)

Puts data at the specified key.

await mogu.put("myKey", { data: "value" });
on(key: string, callback: (data: any) => void)

Subscribes to updates on a specific key.

mogu.on("myKey", (data) => {
  console.log("Updated data:", data);
});

Backup Management

backup()

Performs data backup.

const hash = await mogu.backup();
console.log("Backup hash:", hash);
restore(hash: string)

Restores data from a backup.

const success = await mogu.restore("backupHash");
removeBackup(hash: string)

Removes a specific backup.

await mogu.removeBackup("backupHash");
compareBackup(hash: string)

Compares a backup with local data.

const comparison = await mogu.compareBackup("backupHash");
console.log("Comparison results:", comparison);

Interfaces

interface MoguOptions {
  key?: string;
  storageService?: Web3StashServices;
  storageConfig?: Web3StashConfig;
  server?: any;
  useIPFS?: boolean;
}

interface BackupFileData {
  fileName: string;
  content: string | object;
}

Error Handling

The SDK includes comprehensive error handling. All methods that might fail throw errors that should be handled with try/catch:

try {
  await mogu.backup();
} catch (error) {
  console.error("Backup error:", error);
}

Advanced Usage Examples

Real-Time Synchronization

// Sync configuration
const mogu = new Mogu({ useIPFS: true });

// Subscribe to updates
mogu.on("documents", (data) => {
  console.log("Documents updated:", data);
});

// Update data
await mogu.put("documents", { new: "content" });

Automatic Backup Management

const mogu = new Mogu({
  storageService: "pinata",
  storageConfig: {
    apiKey: process.env.PINATA_API_KEY,
    apiSecret: process.env.PINATA_API_SECRET
  }
});

// Periodic backup
setInterval(async () => {
  try {
    const hash = await mogu.backup();
    console.log("Automatic backup completed:", hash);
  } catch (error) {
    console.error("Automatic backup error:", error);
  }
}, 3600000); // every hour

Testing

The project includes unit and integration tests to ensure code robustness and stability.


File Structure

The project is structured in a modular way, with each component separated and well-defined.


License

Mogu is released under the MIT license.