Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@websdk/nap

Package Overview
Dependencies
Maintainers
2
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@websdk/nap - npm Package Compare versions

Comparing version 0.11.0 to 0.11.1-updating-middleware.0

40

lib/nap.js

@@ -16,8 +16,8 @@ (function (global, factory) {

var nap = { environment: {} };
var nap = {
environment: {}
};
nap.web = newWeb;
nap.is = is;
nap.into = into;
nap.negotiate = {

@@ -28,3 +28,2 @@ selector: bySelector,

};
nap.responses = {

@@ -43,5 +42,2 @@ ok: ok,

if (!node) return;
// TODO: This breaks d3; presumably because there's a discrepancy in domino CustomEvent vs. jsdom CustomEvent
// node.dispatchEvent && node.dispatchEvent(new CustomEvent("update"))
res.body(node);

@@ -148,12 +144,11 @@ };

function bySelector() {
var options = toArray(arguments).reduce(function (curr, next) {
if (isStr(next)) curr.push({ selector: next });else curr[curr.length - 1].fn = next;
if (isStr(next)) curr.push({
selector: next
});else curr[curr.length - 1].fn = next;
return curr;
}, []);
return function (node, cb) {
var called = false,
cb = cb || noop;
called = options.some(function (option) {

@@ -166,3 +161,2 @@ if (is(node, option.selector)) {

});
if (!called) cb("No matching selector");

@@ -173,3 +167,5 @@ };

function wrap(fn, stack) {
return stack.reduce(middleware, fn);
return function wrapped() {
stack.reduce(middleware, fn).apply(null, arguments);
};
}

@@ -202,5 +198,3 @@

metadata || (metadata = {});
handler = wrap(handler, middleware);
resources[name] = {

@@ -212,3 +206,2 @@ name: name,

};
routes.add(ptn, function (params) {

@@ -227,5 +220,6 @@ return {

web.req = function (path, cb) {
var req = isStr(path) ? { uri: path } : path,
var req = isStr(path) ? {
uri: path
} : path,
cb = cb || noop;
req.web = web;

@@ -236,4 +230,5 @@ req.method || (req.method = "get");

req.headers.accept || (req.headers.accept = "application/x.nap.view");
var match = find(req.uri) || { fn: wrap(notFound, middleware) };
var match = find(req.uri) || {
fn: wrap(notFound, middleware)
};
req.params = match.params;

@@ -246,3 +241,3 @@ match.fn.call(null, req, cb);

if (!arguments.length) return web;
middleware = toArray(arguments).reverse().concat(middleware);
middleware.unshift.apply(middleware, toArray(arguments).reverse());
return web;

@@ -252,5 +247,5 @@ };

web.uri = function (ptn, params) {
var meta = resources[ptn];
if (meta) ptn = meta.ptn;
var parts = rhumb._parse(ptn);

@@ -262,2 +257,3 @@

}
return [uri, part.input].join("/");

@@ -264,0 +260,0 @@ }, "");

{
"name": "@websdk/nap",
"version": "0.11.0",
"version": "0.11.1-updating-middleware.0",
"description": "Organizing applications into resources",

@@ -5,0 +5,0 @@ "main": "lib/nap.js",

@@ -160,3 +160,5 @@ var rhumb = require('@websdk/rhumb')

function wrap(fn, stack) {
return stack.reduce(middleware, fn)
return function wrapped() {
stack.reduce(middleware, fn).apply(null, arguments)
}
}

@@ -229,3 +231,3 @@

if(!arguments.length) return web
middleware = toArray(arguments).reverse().concat(middleware)
middleware.unshift.apply(middleware, toArray(arguments).reverse())
return web

@@ -232,0 +234,0 @@ }

@@ -19,6 +19,6 @@ var nap = require('../src/nap')

, w2 = nap.web()
, fn = function() {}
, fn = function() { t.ok(true, 'resource added to w1') }
w1.resource('/wibble', fn)
t.equal(get(w1.resource('/wibble'), 'handler'), fn, 'resource added to w1')
get(w1.resource('/wibble'), 'handler')()
t.notOk(w2.resource('/wibble'), 'resource not added to w2')

@@ -31,6 +31,5 @@ })

var web = nap.web()
, fn = function() { return true }
, fn = function() { t.ok(true, 'resource added') }
web.resource('wobble', '/foo/bar', fn)
t.equal(get(web.resource('wobble'), 'handler'), fn, 'resource added')
t.ok(web.req('/foo/bar'), 'handler called')

@@ -43,6 +42,5 @@ })

var web = nap.web()
, fn = function() { return true }
, fn = function() { t.ok(true, 'resource added') }
web.resource('/foo/{val}', fn)
t.equal(get(web.resource('/foo/{val}'), 'handler'), fn, 'resource added')
t.ok(web.req('/foo/bean'), 'handler called')

@@ -94,30 +92,30 @@ })

var web = nap.web()
, fn_a = function() {}
, fn_b = function() {}
, fn_c = function() {}
, fn_d = function() {}
, fn_a = function() { t.ok(true, 'resource a handler will be called') }
, fn_b = function() { t.ok(true, 'resource b handler will be called') }
, fn_c = function() { t.ok(true, 'resource c handler will be called') }
, fn_d = function() { t.ok(true, 'resource d handler will be called') }
web.resource('/no/metadata/no/params', fn_a)
var a = web.find('/no/metadata/no/params')
t.equal(a.fn, fn_a)
t.deepEqual(a.params, {})
t.deepEqual(a.metadata, {})
a.fn()
t.deepEqual(a.params, {}, 'resource a params exists')
t.deepEqual(a.metadata, {}, 'resource a metadata exists')
web.resource('/with/metadata/no/params', fn_b, { foo: 'bar' })
var b = web.find('/with/metadata/no/params')
t.equal(b.fn, fn_b)
t.deepEqual(b.params, {})
t.deepEqual(b.metadata, { foo: 'bar' })
b.fn()
t.deepEqual(b.params, {}, 'resource a params exists')
t.deepEqual(b.metadata, { foo: 'bar' }, 'resource b metadata exists')
web.resource('/{with}/metadata/and/{params}', fn_c, { baz: 'wibble' })
var c = web.find('/some/metadata/and/fun')
t.equal(c.fn, fn_c)
t.deepEqual(c.params, { with: 'some', params: 'fun' })
t.deepEqual(c.metadata, { baz: 'wibble' })
c.fn()
t.deepEqual(c.params, { with: 'some', params: 'fun' }, 'resource c params exists')
t.deepEqual(c.metadata, { baz: 'wibble' }, 'resource c metadata exists')
web.resource('named', '/also/{with}/metadata/and/{params}', fn_d, { boo: 'moo' })
var d = web.find('/also/some/metadata/and/fun')
t.equal(d.fn, fn_d)
t.deepEqual(d.params, { with: 'some', params: 'fun' })
t.deepEqual(d.metadata, { boo: 'moo' })
d.fn()
t.deepEqual(d.params, { with: 'some', params: 'fun' }, 'resource d params exists')
t.deepEqual(d.metadata, { boo: 'moo' }, 'resource d metadata exists')
})

@@ -124,0 +122,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc