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

@dsbn/unrest

v0.1.1

Published

A websocket api for realtime communication and collaboration.

Downloads

8

Readme

Usage

npm i -D @dsbn/unrest
// main.js
import Vue from 'vue'
import Unrest from '@dsbn/unrest'

Vue.use(Unrest, {
  application: 'your-site.com/data/v1/my-application',
  token: Promise.resolve(`my.JWT.token`),
  vue: Vue
})

The ~~Dream~~Realcode

// my-component.vue
<script>
  export default {
    methods: {
      setupDB() {
        this.$db.create('new-bucket', {
          create: 'Role:Developers,Role:ERT',
          read: '*', // readable by anyone
          write: '@self'
        })

        this.$db.list() // return all buckets for app-slug
        this.$db.update('new-bucket', {new_permissions})
        this.$db.remove('new-bucket') // and all documents inside
      }
    },
    data() {
      let [items, othertable] = this.$db.sync('new-bucket', 'othertable')
      othertable.on('delete', (deletedItem) => doSomething());
      return { items, othertable }
    }
  }
</script>

<template>
  <ul>
    <!-- .new() return a promise if you need it -->
    <li @click="items.new({ template_object })">Create New</li>
    <li v-for="item in items">
      <!-- patch only the `title` property -->
      <input type="text" v-model="item.title" @keyup="item.patch('title')">
      <!-- PUT the entire object with .save() -->
      <input type="checkbox" v-model="item.done" @change="item.save()">
      <button @click="item.remove()"></button>
    </li>
  </ul>
</template>

Methods

For modifing the bucket structure, requires Admin permissions. AKA having your Role: be in the Admin section of an application.

$db.list() : Promise<Array<String>>

Returns a list of buckets that are attached to this application.

$db.create(name, permissions) : Promise<Object>

Returns a promise for when the given bucket named name is created with the given permissions. An example of a permission object is below.

{ create: 'Role:Developers,Role:ERT',
  read: '*',
  write: '@self' }

The above object allows only users with the "Developer" or "ERT" roles to create new documents, allow anyone to read anyone elses document inside this bucket, but restrict the editors of a document to only the author who created it.

$db.update(name, permissions) : Promise<Object>

It's the exact same as .create, just for an existing bucket.

$db.remove(name) : Promise<Object>

Does what you'd expect.

$db.sync(bucket...) : Array<Table>

Begins syncing the entire bucket, all documents inside, into the returned Object asyncronously.

let [ people ] = this.$db.sync('people')

...
<li v-for="person in people">{{person.name}}</li>

table.new(obj) : Promise<Item>

Creates a new object, will inject the given object with the ._id property when saved to the database. Will also resolve the returned promise.

table.on(event, callback<Item>)

Allows you to recieve events as they happen and react to them. create patch update delete or meta.

table.synced : Promise

This property is a promise that is resolved when the entire table has been synced to the client. AKA fully "loaded".

item.save()

Does a PUT, saving all properties attached to the object.

item.remove()

Removes the item from the database, doesn't change the local item instance at all.

item.patch(property)

Saves a single updated property of the item. Good for multi-user collaberation without squashing changes.

let item = $db.tables['some-table']['111111111']
item.something = 'new-val'
item.patch('something')