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

freedb

v1.0.1

Published

Key-Value Database based on github.com

Downloads

9

Readme

freedb

A lightweight solution to use a cloud Key-Value database based on github.com.

Install

npm install freedb --save

Building

See BUILD.md.

Usage

import Free from 'freedb';

const kv = new Free.KV({
  // This is my public test account and token, only used for test and CI.
  // If you want to have your own database,
  // Then you need to create a repository and generate a token.
  host: '[email protected]:Gcaufy-Test/test-database.git',
  token: 'your_github_repo_token'
});

kv.set('mykey', 'myvalue').then(res => {
  console.log(res.raw_url);
});

How to generate a token

  1. Create or use your own github.com account and login.
  2. Go to: Settings -> Developer settings -> Personal access tokens -> Generate new token
  3. Select scopes: "repo" to make sure you grant access.

API:

  • Create a KV instance

    new Free.KV(option: DataBaseOption):

    DataBaseOption {
        // host: github clone links, support both https/ssh links
        host: string;
        // token: OAuth token, make sure you have read/write access for the repo
        token: string;
        // db: Basiclly it's a directory, default value is "default"
        db?: string;
        // branch: git branch, default value is "master"
        branch?: string;
        // cipher: if is a string, then treat as a secret key for aes192 for both key and value. or you can customize a encryt and decrypt function
        cipher?: CipherOption | string;
        // debug: show action log or not.
        debug?: boolean;
    }
    
    CipherOption {
      // secret key for encrypt
      secret: string;
      // customize encrypt algorithm, default value is ase192 encrypt algorithm
      encode: (str: string): string;
      // customize decrypt algorithm, default value is ase192 decrypt algorithm
      decode: (str: string): string;
    }
  • KV instance methods

    1. use(db: string): void

    Switch database. can be a non-exist database.

    1. keys(): Promise<KeyRecord[]>

    List all keys in current database;

    1. exist(key: string): Promise

    Check a key exist or not in current database;

    1. get(key: string): Promise

    Get a key record in current database;

    1. set(key: string, value: string): Promise

    Set a value for a key. Will create a key if a key do not exist;

    1. append(key: string): Promise

    Append a value for a key. Will create a key if a key do not exist;

    KeyRecord {
      // Key content
      content?: string;
      // Key name
      name?: string;
      // Key content size, if the key do not exist, then size = -1
      size?: number;
      // Key git raw url
      raw_url?: string;
      // Key git html url
      html_url?: string;
      // Key git commit hash if there is
      commit?: string;
    }

How to protect your data

There are two way to protect your data.

  1. Encrypt you key and value in CipherOption
new GitDB.KV({
  host: '[email protected]:Gcuafy-Test/test-database',
  token: 'mytoken',
  cipher: {
    secret: 'my secret key',
    // Default value is using ase192 encrypt algorithm
    encode (str) {
      return MyEncryptMethod(str);
    },
    // Default value is using ase192 decrypt algorithm
    decode (str) {
      return MyDecryptMethod(str);
    }
  }
})
  1. Make the repository private. Simply and easy. Github support private repository