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

backbone.wamp

v2.0.0

Published

WAMP protocol for Backbone Models and Collections (WebSocket)

Downloads

18

Readme

Backbone.WAMP

Backbone.WAMP replace your classic REST protocol, based on AJAX, to modern WAMP protocol, based on WebSockets. You can read more about here.

Dependencies

Backbone AutobahnJS

Overview example

/************
   browser
************/

window.WAMP_OTHER_ID = "nodejs";
window.WAMP_CONNECTION = new autobahn.Connection({
  url: "ws://127.0.0.1:9000/ws",
  realm: "realm1"
});

WAMP_CONNECTION.onopen = function () {
  var Collection = WampCollection.extend({
    url: "test_collection"
  });
  var collection = new Collection();
  collection.fetch(); // call wampRead below
  collection.create({ // call wampCreate below
    age: 36,
    name: "John"
  }, {
    success: function () {
      collection.first().destroy(); // call wampDelete below
    }
  });
};

WAMP_CONNECTION.open();



/**********
   nodejs
**********/

global.WAMP_MY_ID = "nodejs";
global.WAMP_CONNECTION = new autobahn.Connection({
  url: "ws://127.0.0.1:9000/ws",
  realm: "realm1"
});

WAMP_CONNECTION.onopen = function () {
  var Collection = WampCollection.extend({
    url: "test_collection",
    wampRead: function () {
      // called via fetch
      // need return data or promise
    },
    wampCreate: function (sendOptions) {
      sendOptions.data.age === 36; // true
      sendOptions.data.name === "John"; // true
      // need return data or promise
    },
    wampDelete: function (sendOptions) {
      // sendOptions.extra.wampModelId contain id of model
      // need return data or promise
    }
  });

  collection = new Collection();
};

WAMP_CONNECTION.open();

API

wampConnection / WAMP_CONNECTION

Before create instances of WampModel / WampCollection, you need eastablish autobahn connection and link it to global WAMP_CONNECTION or specific wampConnection for WampModel / WampCollection.

window.WAMP_CONNECTION = new autobahn.Connection({
  url: "ws://127.0.0.1:9000/ws",
  realm: "realm1"
});

var wampConnection = new autobahn.Connection({
  url: "ws://127.0.0.1:9000/ws",
  realm: "realm2"
});

WAMP_CONNECTION.onopen = function () {
  var Collection = WampCollection.extend({
    url: "test_collection"
  });
  var collection = new Collection(); // this collection used WAMP_CONNECTION
};

wampConnection.onopen = function () {
  var Collection = WampCollection.extend({
    url: "test_collection2"
    wampConnection: wampConnection
  });
  var collection = new Collection(); // this collection used wampConnection
}

WAMP_CONNECTION.open();
wampConnection.open();

wampMyId / WAMP_MY_ID

This unique peer-id of current environment, with which you want interact from other environments.

global.WAMP_MY_ID = "nodejs";
global.WAMP_CONNECTION = new autobahn.Connection({
  url: "ws://127.0.0.1:9000/ws",
  realm: "realm1"
});

WAMP_CONNECTION.onopen = function () {
  var Collection = WampCollection.extend({
    url: "test_collection",
  });

  var Model = WampModel.extend({
    urlRoot: "test_model"
    wampMyId: "nodejs2"
  });

  var collection = new Collection(); // this available on "nodejs"
  var model = new Model(); // this available on "nodejs2"
};

WAMP_CONNECTION.open();

wampOtherId / WAMP_OTHER_ID

This means peer-id of environment, with which you want interact from current environment.

window.WAMP_OTHER_ID = "nodejs";
window.WAMP_CONNECTION = new autobahn.Connection({
  url: "ws://127.0.0.1:9000/ws",
  realm: "realm1"
});

WAMP_CONNECTION.onopen = function () {
  var Collection = WampCollection.extend({
    url: "test_collection",
  });

  var Model = WampModel.extend({
    urlRoot: "test_model"
    wampOtherId: "nodejs2"
  });

  var collection = new Collection(); // this will interact with "nodejs"
  var model = new Model(); // this will interact with "nodejs2"
};

WAMP_CONNECTION.open();

constructor

When you create instances of WampModel / WampCollection, this automatically register listeners, using wampMyId / WAMP_MY_ID and urlRoot / url, if it present. For ignoring this, need pass to constructor - wampNoAttach option. For catching each registering need pass to constructor - wampRegister callback-option.

window.WAMP_CONNECTION = new autobahn.Connection({
  url: "ws://127.0.0.1:9000/ws",
  realm: "realm1"
});

WAMP_CONNECTION.onopen = function () {
  var Collection = WampCollection.extend({
    url: "test_collection",
  });

  var Model = WampModel.extend({
    wampMyId: "browser"
  });

  var Model2 = WampModel.extend({
    urlRoot: "model2",
    wampMyId: "browser"
  })

  var collection = new Collection(); // no register listeners, wampMyId / WAMP_MY_ID ommited
  var model = new Model(); // no register listeners, urlRoot ommited
  var model2 = new Model2({}, {wampNoAttach: true}); // no register listeners, pass specific option
  model2 = new Model2({}, {wampRegister: function (errOrReg) { // register listeners
    // calling for registering each action: create | read | update | delete | patch
  }})
};

WAMP_CONNECTION.open();

wampCreate, wampRead, wampUpdate, wampDelete, wampPatch

This hooks automatically registers, when create instances of WampModel / WampCollection, if exists wampMyId / WAMP_MY_ID and urlRoot / url and not pass wampNoAttach option.

Received param: sendOptions

sendOptions.data contains JSON-parsed model for create, update, patch actions. Or GET-params for read action of model/collection. sendOptions.extra contain any extra information, which you can send in options.wampExtra Built-in options in sendOptions.extra:

  • wampModelId of specific model, if needed
  • wampMyId of another environment
Return

Need return data or promise, that resolved to data. For error need return new autobahn.Error(...) or promise, that resolve new autobahn.Error(...) For example, see Overview example above.

wampGetUri / WAMP_GET_URI

By default, via methods save, fetch, e.t.c. generated WebSocket messages as is peerId.uri.action Example: "nodejs.test_collection.create" You can overwrite template if needed via wampGetUri / WAMP_GET_URI, that

Received params: peerId, uri, action
Return: string of WebSocket message

wampAuth / WAMP_AUTH

When defined, will be called before wampCreate, wampRead, wampUpdate, wampDelete, wampPatch. If it's return non true value or promise, that resolved to non true, wampCreate, wampRead, wampUpdate, wampDelete, wampPatch not be called.

Received params: uriOptions, sendOptions

uriOptions contain peerId, uri, action

more about sendOptionsin wampCreate, wampRead, ... partition

Return: true or promise, that resolved to true (if auth passed)
global.WAMP_MY_ID = "nodejs";
global.WAMP_CONNECTION = new autobahn.Connection({
  url: "ws://127.0.0.1:9000/ws",
  realm: "realm1"
});

WAMP_CONNECTION.onopen = function () {
  var Collection = WampCollection.extend({
    url: "test_collection",
    wampAuth: function (uriOptions, sendOptions) {
      // it pseudo code with concept
      return new Promise(function (resolve) {
        db.find({peer: sendOptions.extra.wampMyId}).then(function (finded) {
          resolve(finded) // if finded === true, auth passed
        })
      });
    },
    wampRead: function () {
      // this called, if wampAuth return promise, that resolved to true
    }
  });

  var collection = new Collection();
};

WAMP_CONNECTION.open();
Session

This can be useful for wampAuth. For session mechanism need dynamically generate wampMyId. Example: browser_0dbee552-46e0-4c7c-aa4e-e1341dc00b18 Use any UUID, GUID, e.t.c. generator, maybe node-uuid

wampUnregister

Call this method directly on instances of WampModel / WampCollection for unregistering wampCreate, wampRead, ... methods.

Received params: actions, callback

actions it array, for example ["read", "delete"] If omitted, will unregister all actions

callback called per each unregistering action

global.WAMP_MY_ID = "nodejs";
global.WAMP_CONNECTION = new autobahn.Connection({
  url: "ws://127.0.0.1:9000/ws",
  realm: "realm1"
});

WAMP_CONNECTION.onopen = function () {
  var Collection = WampCollection.extend({
    url: "test_collection"
  });

  var collection = new Collection();
  collection.wampUnregister(null, function (err, uri) {
    // called per each unregistering action
  });
};

WAMP_CONNECTION.open();

License

(The MIT License)

Copyright (c) 2015 Vladislav Botvin <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

License of AutobahnJS

Copyright (c) 2011-2014 Tavendo GmbH.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.