0.0.1 • Published 2 years ago

fvideen-gundb-sdk v0.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

FVIdeen - GunDB SDK Client Library

Examples

Clone it

  • git clone <this-repo-url>
  • cd <repo-name>

Install

  • npm run install

Build

  • npm run build

Dev

  • npm run dev

Test

  • npm run test

How to use

  • Includes script into html page
    <script src="../dist/fvideen-gundb-sdk.js"></script>

OR

  • Includes require statament in node file
const { SdkClient } = require('fvideen-gundb-sdk')
  • Instantiate new SDK from static asset javascript sdk bundle
  <script type="text/javascript">
      const sdk = new window['fvideen-gundb-sdk'].SdkClient('fvideen.local.1', [avaliacao + '/gun'])
  </script>

OR

  • Instantiate class into node file
const sdk = new SdkClient(
  'db-namespace', 
  ['http://server-peer:1/gun', 'http://server-peer:2/gun', 'http://server-peer:3/gun']
  axios, // (Optional) Custom axiosInstance or SDK creates new one
  gun// (Optional) Custom IGunChainReference to wrapper SDK with db namespace, etc
  )
  • Retrieve a root node, gets new node and subscribe it
  <script type="text/javascript">
      sdk
        .node() // gets root node
        .get('styles/input/h1') // gets new node from root node
        .on((item, id) => { // subscribe on created/updated data in this new node
          if (!item) return
          console.log('#>>', id) // the new node key, e.g. 'styles/input/h1'
          console.log('#>>', item) // the item created/updated in this new node
        })
  </script>
  • Set and retrieve a root child node like an array list items
  <script type="text/javascript">
    // Id to todo, this should have unique identification for each todo into list
    const todoId = 1
    // Gets new root child node to todo node
    const todoNode = sdk.node().get(todoId) 
    // Put todo data
    todoNode.put({ id: todoId, title: 'Sync internet data for free to everbody =)' })
    // Gets new root child node to todo list
    const todoListNode = sdk.node().get('todos')

    // Adds todo node into todo array list node, this is a link ref only into graph
    todoNodeList.set(todoNode)

    // Maps all items into this list and subscribe each item into array list
    todoListNode
      .map() 
      .on((todo, id) => { 
        console.log('#>>', id) // internal id created from sdk to item into array list 
        console.log('#>>', todo) // todo item created/updated in this array list node of To Do's
      })
  </script>

Scripts

  • npm run build: Build library.
  • npm run dev: Run dev mode, waiting for changes to run lint and unit tests.
  • npm run test: Run mocha unit tests.
  • npm run compile: Clean temp files and e directories.
  • npm run coverage: Run unit tests and coverage with nyc.
  • npm run release: Init git flow release from next package version, patch, git flow.
  • npm run release:minor: Init git flow release from next package version, minor, git flow.
  • npm run release:major: Init git flow release from next package version, major, git flow.
  • npm run release:finish: Finish current releas, git flow.