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

ohmygraph

v1.0.10

Published

Easily generate a graphs/REST-clients from json api-modelspecifications. Like restangular/traverse/backbone/restful but more atheist-style.

Downloads

12

Readme

Usage:

npm install ohmygraph

or in the browser (6k when gzipped):

<script type="text/javascript" src="ohmygraph.min.js"></script> 

Try the online editor

Video

VIDEO

Example: github api

ohmygraph = require 'ohmygraph'

graph =
  repositories:
    type: "array"
    items: [{"$ref":"#/repository"}]
    data: { sort:'stars',q:'ohmy',order:'desc' }
    request:
      get:
        config:
          method: 'get'
          url: '/search/repositories'
          payload:
            q: '{repositories.data.q}'
            sort: '{repositories.data.sort}'
            order: '{repositories.data.order}'
        data: "{response.items}"
  repository:
    type: "object"
    properties: { ..... }
    data: {}
    request:
      get:
        config:
          method: 'get'
          url: '/repos/{repository.data.full_name}'
          payload: {}
        data: "{response}"
      post:
        type: "request"
        config:
          method: "post"
          url: '/repos/{repository.data.full_name}'
          payload:
            'full_name': '{repository.data.full_name}'


omg = ohmygraph.create graph, {baseurl: "https://api.github.com",verbose:2}
omg.init.client()
client = omg.graph

client.repositories.on 'data', (repositories) ->
  console.log "on repositories"
  repositories[0].get()

client.repository.on 'data', (repository) ->
  console.log "on repository"
  console.dir repository

# lets request data!
client.repositories.get()
client.repositories.get {q:"foo"}

Features

  • modular multi-api REST client
  • resource linking (using a graph)
  • easy to use with API's generated from json-model (just convert the model)
  • only deal with dataobjects in javascript, not with REST code
  • datamodel does not dictate api model (like backbone)
  • fully customizable webcalls using fetch, [docs here](see https://www.npmjs.com/package/whatwg-fetch)

Example: combining API's

api_one = {..}
api_two = {..}

omg = ohmygraph.create();
omg.graph = api_one;
for (k in api_two) omg.graph[k] = api_two[k];

omg.init.client();

Example: patching/extending api-calls

Sometimes an jsonmodel needs to be patched. Luckily, json-ref-lite's "$extend" keys are automatically parsed.

Api

graph = graph

access your resolved graph here

create(graph = {},opts = {})

create graph

init.client()

generate client functions from graph(after create())

extend()

extend "$extend" keys in graph

resolve()

resolve "$ref" references in graph

export_functions(return_array_boolean)

dump client functions as string or array

yournode.bindrequests(node)

autobind client requesthandlers on node

yournode.trigger(event,data)

trigger an event on your nodeyournode.trigger('foo',{data:'bar'}) yournode.on(event,cb) register an event on your nodeyournode.on( 'foo', function(){} )

yournode.clone()

call clone() on a node to keep the original intact

get(node)

get node with name x

clone(obj)

deep clone object utility function

onWarning(err)

customizable warning function

onError()

customizable error/catch function

Inspired by

This work was inspired by the thought that linking of resources could happen on a json model-level, instead of only on a RESTful level (interpreting links from responses). Ohmygraph is pretty much jsonbased and framework- and API-agnostic, but it was inspired by:

backbone/exoskeleton

requires particular api design

restangular

angular based router which requires angular + a particular api design.

restful.js

restangular without angular but with particular api design

traverson

no restmapping, only linking