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

apiway

v0.0.10

Published

Client side for Apiway framework

Downloads

8

Readme

Apiway - Client side

Server side

Getting started

# Install
$ npm install apiway --save                
// Require
import { Api, Resource, Store } from "apiway";

Hierarchy

EventEmitter 
|
|---> Api             
|
|---> Resource
|
|---> Store

EventEmitter docs

Api

Api provides an requests interface to actions of controllers server.

Methods

Api.connect( address[, options ] )

Open websocket connection to Apiway server, options:

  • aliveDelay - seconds between ping sendings, default: 0 (off)
Api.query( "controller.action", params )

Make query to controller action on server side with params, return Promise.

Api.send( event, data )

Send your custom event with data.

Api.disconnect()

Close connection.

Api.beforeReadyPromise( callback )

Set a method that returns a promise. Called after the connection and triggering ready/unready events. It can be used for pre-authentication before ready event.

Api.onReady( callback, context )  # call on every trigger
Api.oneReady( callback, context ) # call on first trigger

Attach callback with context to "ready" event.

Api.offReady( callback, context )

Detach callback with context from "ready" event.

Api.onUnready( callback, context )  # call on every trigger
Api.oneUnready( callback, context ) # call on first trigger

Attach callback with context to "unready" event.

Api.offUnready( callback, context )

Detach callback with context from "unready" event.

Example

Api
  .connect( "ws://localhost:3000", { aliveDelay: 5000 } )
  .beforeReadyPromise( function(){
    return Api.query( "Users.auth_by_token", { token: Cookie.get( "token" ) } );
  })
  .oneReady( function(){
    RouterRun();
  });
Api.query( "Messages.new", { text: "Hello world!" } )
  .then(  (e)=>{ console.log( "success" ) } )
  .catch( (e)=>{ console.log( "failure" ) } );

Resource

Resources provide access to relevant data and automatically synchronized when they change.

Create

let resource = new Resource( resourceName, params );

Create new resource with params.

Methods

resource.name

Getter to resource name.

resource.data

Getter to resource data.

resource.get( paramName )

Return value of resource param.

resource.set( { paramName: paramValue, paramName: paramValue } )

Set values of resource params.

resource.unset( paramName )

Remove param from resource params.

resource.onChange( callback, context )  # call on every trigger
resource.oneChange( callback, context ) # call on first trigger

Attach callback with context to "change" event.

resource.offChange( callback, context )

Detach callback with context from "change" event.

resource.onError( callback, context )  # call on every trigger
resource.oneError( callback, context ) # call on first trigger

Attach callback with context to "error" event.

resource.offError( callback, context )

Detach callback with context from "error" event.

Example

let currentUser = new Resource( "CurrentUser" );
currentUser
  .onChange( ( e )=>{ console.log( "Data of current user:", currentUser.data ) })
  .onError(  ( e )=>{ console.log( "Error", e ) });

// > Error auth_error

Api.query( "Users.auth_by_name", { name: "Bob" } );

// > Data of current user: {id: 1, name: "Bob"}

let messages = new Resource( "Messages", { limit: 3 } );
messages.onChange( ()=>{ console.log( "Messages:", messages.data ) } );

// > Messages [{text: "Hello world"}, {text: "Hello world"}, {text: "Hello world"}]

messages.set({ limit: 2 });

// > Messages [{text: "Hello world"}, {text: "Hello world"}]

messages.get( "limit" );

// > 2

Store

Store is a simple object for the storage data of your application and access to them from different parts of the application.