08-27-周三_17-09-29
This commit is contained in:
4
node_modules/dnode-protocol/.travis.yml
generated
vendored
Normal file
4
node_modules/dnode-protocol/.travis.yml
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- 0.4
|
||||
- 0.6
|
4
node_modules/dnode-protocol/LICENSE
generated
vendored
Normal file
4
node_modules/dnode-protocol/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
Copyright 2010 James Halliday (mail@substack.net)
|
||||
|
||||
This project is free software released under the MIT license:
|
||||
http://www.opensource.org/licenses/mit-license.php
|
139
node_modules/dnode-protocol/README.markdown
generated
vendored
Normal file
139
node_modules/dnode-protocol/README.markdown
generated
vendored
Normal file
@@ -0,0 +1,139 @@
|
||||
dnode-protocol
|
||||
==============
|
||||
|
||||
This module implements the dnode protocol in a reusable form that is presently
|
||||
used for both the server-side and browser-side dnode code.
|
||||
|
||||
[Read about the protocol itself here.](https://github.com/substack/dnode-protocol/blob/master/doc/protocol.markdown)
|
||||
|
||||
[](http://travis-ci.org/substack/dnode-protocol)
|
||||
|
||||
example
|
||||
=======
|
||||
|
||||
``` js
|
||||
var proto = require('dnode-protocol');
|
||||
|
||||
var s = proto({
|
||||
x : function (f, g) {
|
||||
setTimeout(function () { f(5) }, 200);
|
||||
setTimeout(function () { g(6) }, 400);
|
||||
},
|
||||
y : 555
|
||||
});
|
||||
var c = proto();
|
||||
|
||||
s.on('request', c.handle.bind(c));
|
||||
c.on('request', s.handle.bind(s));
|
||||
|
||||
c.on('remote', function (remote) {
|
||||
function f (x) { console.log('f(' + x + ')') }
|
||||
function g (x) { console.log('g(' + x + ')') }
|
||||
remote.x(f, g);
|
||||
});
|
||||
|
||||
s.start();
|
||||
c.start();
|
||||
```
|
||||
|
||||
***
|
||||
|
||||
```
|
||||
f(5)
|
||||
g(6)
|
||||
```
|
||||
|
||||
methods
|
||||
=======
|
||||
|
||||
``` js
|
||||
var protocol = require('dnode-protocol')
|
||||
```
|
||||
|
||||
var proto = protocol(cons, opts={})
|
||||
-----------------------------------
|
||||
|
||||
Create a new protocol object with a constructor `cons` and an optional callback
|
||||
wrapper `wrap`.
|
||||
|
||||
`cons` should be a function, in which case it will be used to create an instance
|
||||
by `new cons(remote, proto)` where `remote` is an empty reference to the remote
|
||||
object before being populated and `proto` is the protocol instance.
|
||||
|
||||
If you return an object in `cons` the return value will be used
|
||||
(`new` does that part).
|
||||
|
||||
If you pass in a non-function as `cons`, its value will be used as the instance
|
||||
directly.
|
||||
|
||||
You can optionally specify `opts.wrap` and `opts.unwrap` to wrap and unwrap
|
||||
remote values for implementing weakmaps or marking callbacks.
|
||||
|
||||
The return value of `opts.wrap(cb, id)` will be stored in `proto.callbacks.remote[id]`
|
||||
and `opts.unwrap(ref, id)` will be called with the `ref` obtained from `wrap()`
|
||||
previously to turn `ref` back into a `cb`.
|
||||
|
||||
proto.handle(req)
|
||||
-----------------
|
||||
|
||||
Handle a request object emitted by the request event, calling the method the
|
||||
request mentions with the provided arguments.
|
||||
|
||||
proto.request(method, args)
|
||||
---------------------------
|
||||
|
||||
Emit a request event for the method id `method` and the raw arguments `args`.
|
||||
The args will be scrubbed for callbacks and emitted in normal form suitable for
|
||||
passing to `JSON.stringify()`.
|
||||
|
||||
proto.start()
|
||||
-------------
|
||||
|
||||
Begin the methods exchange. All listeners should be bound before this function
|
||||
is called.
|
||||
|
||||
proto.cull(id)
|
||||
--------------
|
||||
|
||||
Instruct the opposing connection to drop all references to the callback
|
||||
specified by `id`.
|
||||
|
||||
events
|
||||
======
|
||||
|
||||
proto.on('request', function (req) { ... })
|
||||
-------------------------------------------
|
||||
|
||||
Emitted when a request is ready to be sent.
|
||||
|
||||
The request should be serialized and passed to the opposing connection's
|
||||
`.handle()`.
|
||||
|
||||
proto.on('remote', function (remote) { ... })
|
||||
---------------------------------------------
|
||||
|
||||
Emitted when the remote reference has been populated.
|
||||
|
||||
proto.on('fail', function (err) { ... })
|
||||
----------------------------------------
|
||||
|
||||
Emitted when there is a non-fatal failed request.
|
||||
|
||||
proto.on('error', function (err) { ... })
|
||||
-----------------------------------------
|
||||
|
||||
Emitted when there is a fatal exception one of the local callbacks.
|
||||
|
||||
install
|
||||
=======
|
||||
|
||||
With [npm](http://npmjs.org) do:
|
||||
|
||||
```
|
||||
npm install dnode-protocol
|
||||
```
|
||||
|
||||
license
|
||||
=======
|
||||
|
||||
MIT
|
90
node_modules/dnode-protocol/doc/protocol.markdown
generated
vendored
Normal file
90
node_modules/dnode-protocol/doc/protocol.markdown
generated
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
the protocol
|
||||
============
|
||||
|
||||
dnode uses newline-terminated JSON messages. Each side of the connection may
|
||||
request that a method be invoked on the other side.
|
||||
|
||||
data fields
|
||||
-----------
|
||||
|
||||
All messages have this format:
|
||||
|
||||
* method :: String or Integer
|
||||
* arguments :: Array
|
||||
* callbacks :: Object
|
||||
* links :: Array
|
||||
|
||||
When the method field is a string, it refers to a named method at the remote.
|
||||
When the method field is an integer, it refers to an anonymous function
|
||||
declared in the callbacks field of a previous request.
|
||||
|
||||
The arguments field contains the data to supply the remote method or callback.
|
||||
The callbacks field maps an integral callback ID to an Array of elements
|
||||
representing the callback's path in the arguments structure. For instance,
|
||||
an arguments array before transformation of
|
||||
|
||||
[ 50, 3, { "b" : function () {}, "c" : 4 }, function () {} ]
|
||||
|
||||
could result in a callback field of
|
||||
|
||||
{ 103 : [ 2, "b" ], 104 : [ 3 ] }
|
||||
|
||||
if the functions were assigned IDs of 103 and 104 from left to right
|
||||
respectively. Function 103 is in the object at element index 2 and at the key
|
||||
"b", so its path is [ 2, "b" ]. Function 104 is just at index 3 in the argument
|
||||
field so its path is just [ 3 ].
|
||||
|
||||
The contents of the arguments array at a callback location is not used, so it
|
||||
may contain any value or may be left undefined.
|
||||
|
||||
The Array and Object fields can be omitted, in which case they default to [] and
|
||||
{}.
|
||||
|
||||
methods
|
||||
-------
|
||||
|
||||
After the connection is established, each side should send a message with the
|
||||
method field set to "methods". The arguments fields should contain an array with
|
||||
a single element: the object that should be wrapped. The callbacks field is
|
||||
populated from the arguments array given the procedure above.
|
||||
|
||||
Example of this initial methods message:
|
||||
|
||||
{
|
||||
"method" : "methods",
|
||||
"arguments" : [ { "timesTen" : "[Function]", "moo" : "[Function]" } ],
|
||||
"callbacks" : { "0" : ["0","timesTen"], "1" : ["0","moo"] }
|
||||
}
|
||||
|
||||
Note that the string "[Function]" is just a placeholder and its value is
|
||||
unimportant.
|
||||
|
||||
After methods are exchanged, each side may request methods from the other based
|
||||
on named keys or numeric callback IDs.
|
||||
|
||||
links
|
||||
-----
|
||||
|
||||
An optional field, "links" supports representing cyclic data structures over
|
||||
JSON. The "links" field is an array of hashes with "from" and "to" keys set. The
|
||||
values of the "from" and "two" keys are array encoding paths through the data
|
||||
structure from the root, as in the "callbacks" field.
|
||||
|
||||
Example of a method call with cyclic references:
|
||||
|
||||
{
|
||||
"method" : 12,
|
||||
"arguments" : [ { "a" : 5, "b" : [ { "c" : 5 } ] } ],
|
||||
"callbacks" : {},
|
||||
"links" : [ { "from" : [ 0 ], "to" : [ 0, "b", 1 ] } ]
|
||||
}
|
||||
This example creates a link to the first argument within the first argument's
|
||||
"b" key's second element. The previous data structure could be generated from
|
||||
the following javascript where `fn` comes from the remote:
|
||||
|
||||
var data = { a : 5, b : [ { c : 5 } ] };
|
||||
data.b.push(data);
|
||||
fn(data);
|
||||
|
||||
Note that links need not necessarily be cyclic, they can just more efficiently
|
||||
encode duplicate data, for instance.
|
22
node_modules/dnode-protocol/example/proto.js
generated
vendored
Normal file
22
node_modules/dnode-protocol/example/proto.js
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
var proto = require('../');
|
||||
|
||||
var s = proto({
|
||||
x : function (f, g) {
|
||||
setTimeout(function () { f(5) }, 200);
|
||||
setTimeout(function () { g(6) }, 400);
|
||||
},
|
||||
y : 555
|
||||
});
|
||||
var c = proto();
|
||||
|
||||
s.on('request', c.handle.bind(c));
|
||||
c.on('request', s.handle.bind(s));
|
||||
|
||||
c.on('remote', function (remote) {
|
||||
function f (x) { console.log('f(' + x + ')') }
|
||||
function g (x) { console.log('g(' + x + ')') }
|
||||
remote.x(f, g);
|
||||
});
|
||||
|
||||
s.start();
|
||||
c.start();
|
45
node_modules/dnode-protocol/example/weak.js
generated
vendored
Normal file
45
node_modules/dnode-protocol/example/weak.js
generated
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
var weak = require('weak');
|
||||
var proto = require('../');
|
||||
|
||||
var s = (function () {
|
||||
var cons = {
|
||||
x : function (f, g) {
|
||||
setTimeout(function () { f(5) }, 200);
|
||||
setTimeout(function () { g(6) }, 400);
|
||||
},
|
||||
y : 555
|
||||
};
|
||||
return proto(cons, {
|
||||
wrap : function (cb, id) {
|
||||
return weak(cb, function () {
|
||||
console.log('s.cull(' + id + ')')
|
||||
s.cull(id);
|
||||
});
|
||||
},
|
||||
unwrap : function (ref, id) {
|
||||
var cb = weak.get(ref);
|
||||
return cb || function () {};
|
||||
}
|
||||
});
|
||||
})();
|
||||
|
||||
var c = proto();
|
||||
|
||||
s.on('request', c.handle.bind(c));
|
||||
c.on('request', s.handle.bind(s));
|
||||
|
||||
c.on('remote', function (remote) {
|
||||
function f (x) { console.log('f(' + x + ')') }
|
||||
function g (x) { console.log('g(' + x + ')') }
|
||||
remote.x(f, g);
|
||||
});
|
||||
|
||||
s.start();
|
||||
c.start();
|
||||
|
||||
setTimeout(function () {
|
||||
// switch on the garbage disposal to full blast:
|
||||
var xs = [];
|
||||
for (var i = 0; i < 1000 * 1000; i++) xs.push(function () {});
|
||||
xs = [];
|
||||
}, 1000);
|
125
node_modules/dnode-protocol/index.js
generated
vendored
Normal file
125
node_modules/dnode-protocol/index.js
generated
vendored
Normal file
@@ -0,0 +1,125 @@
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
var scrubber = require('./lib/scrub');
|
||||
var objectKeys = require('./lib/keys');
|
||||
var forEach = require('./lib/foreach');
|
||||
var isEnumerable = require('./lib/is_enum');
|
||||
|
||||
module.exports = function (cons, opts) {
|
||||
return new Proto(cons, opts);
|
||||
};
|
||||
|
||||
(function () { // browsers bleh
|
||||
for (var key in EventEmitter.prototype) {
|
||||
Proto.prototype[key] = EventEmitter.prototype[key];
|
||||
}
|
||||
})();
|
||||
|
||||
function Proto (cons, opts) {
|
||||
var self = this;
|
||||
EventEmitter.call(self);
|
||||
if (!opts) opts = {};
|
||||
|
||||
self.remote = {};
|
||||
self.callbacks = { local : [], remote : [] };
|
||||
self.wrap = opts.wrap;
|
||||
self.unwrap = opts.unwrap;
|
||||
|
||||
self.scrubber = scrubber(self.callbacks.local);
|
||||
|
||||
if (typeof cons === 'function') {
|
||||
self.instance = new cons(self.remote, self);
|
||||
}
|
||||
else self.instance = cons || {};
|
||||
}
|
||||
|
||||
Proto.prototype.start = function () {
|
||||
this.request('methods', [ this.instance ]);
|
||||
};
|
||||
|
||||
Proto.prototype.cull = function (id) {
|
||||
delete this.callbacks.remote[id];
|
||||
this.emit('request', {
|
||||
method : 'cull',
|
||||
arguments : [ id ]
|
||||
});
|
||||
};
|
||||
|
||||
Proto.prototype.request = function (method, args) {
|
||||
var scrub = this.scrubber.scrub(args);
|
||||
|
||||
this.emit('request', {
|
||||
method : method,
|
||||
arguments : scrub.arguments,
|
||||
callbacks : scrub.callbacks,
|
||||
links : scrub.links
|
||||
});
|
||||
};
|
||||
|
||||
Proto.prototype.handle = function (req) {
|
||||
var self = this;
|
||||
var args = self.scrubber.unscrub(req, function (id) {
|
||||
if (self.callbacks.remote[id] === undefined) {
|
||||
// create a new function only if one hasn't already been created
|
||||
// for a particular id
|
||||
var cb = function () {
|
||||
self.request(id, [].slice.apply(arguments));
|
||||
};
|
||||
self.callbacks.remote[id] = self.wrap ? self.wrap(cb, id) : cb;
|
||||
return cb;
|
||||
}
|
||||
return self.unwrap
|
||||
? self.unwrap(self.callbacks.remote[id], id)
|
||||
: self.callbacks.remote[id]
|
||||
;
|
||||
});
|
||||
|
||||
if (req.method === 'methods') {
|
||||
self.handleMethods(args[0]);
|
||||
}
|
||||
else if (req.method === 'cull') {
|
||||
forEach(args, function (id) {
|
||||
delete self.callbacks.local[id];
|
||||
});
|
||||
}
|
||||
else if (typeof req.method === 'string') {
|
||||
if (isEnumerable(self.instance, req.method)) {
|
||||
self.apply(self.instance[req.method], args);
|
||||
}
|
||||
else {
|
||||
self.emit('fail', new Error(
|
||||
'request for non-enumerable method: ' + req.method
|
||||
));
|
||||
}
|
||||
}
|
||||
else if (typeof req.method == 'number') {
|
||||
var fn = self.callbacks.local[req.method];
|
||||
if (!fn) {
|
||||
self.emit('fail', new Error('no such method'));
|
||||
}
|
||||
else self.apply(fn, args);
|
||||
}
|
||||
};
|
||||
|
||||
Proto.prototype.handleMethods = function (methods) {
|
||||
var self = this;
|
||||
if (typeof methods != 'object') {
|
||||
methods = {};
|
||||
}
|
||||
|
||||
// copy since assignment discards the previous refs
|
||||
forEach(objectKeys(self.remote), function (key) {
|
||||
delete self.remote[key];
|
||||
});
|
||||
|
||||
forEach(objectKeys(methods), function (key) {
|
||||
self.remote[key] = methods[key];
|
||||
});
|
||||
|
||||
self.emit('remote', self.remote);
|
||||
self.emit('ready');
|
||||
};
|
||||
|
||||
Proto.prototype.apply = function (f, args) {
|
||||
try { f.apply(undefined, args) }
|
||||
catch (err) { this.emit('error', err) }
|
||||
};
|
6
node_modules/dnode-protocol/lib/foreach.js
generated
vendored
Normal file
6
node_modules/dnode-protocol/lib/foreach.js
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
module.exports = function forEach (xs, f) {
|
||||
if (xs.forEach) return xs.forEach(f)
|
||||
for (var i = 0; i < xs.length; i++) {
|
||||
f.call(xs, xs[i], i);
|
||||
}
|
||||
}
|
12
node_modules/dnode-protocol/lib/is_enum.js
generated
vendored
Normal file
12
node_modules/dnode-protocol/lib/is_enum.js
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
var objectKeys = require('./keys');
|
||||
|
||||
module.exports = function (obj, key) {
|
||||
if (Object.prototype.propertyIsEnumerable) {
|
||||
return Object.prototype.propertyIsEnumerable.call(obj, key);
|
||||
}
|
||||
var keys = objectKeys(obj);
|
||||
for (var i = 0; i < keys.length; i++) {
|
||||
if (key === keys[i]) return true;
|
||||
}
|
||||
return false;
|
||||
};
|
5
node_modules/dnode-protocol/lib/keys.js
generated
vendored
Normal file
5
node_modules/dnode-protocol/lib/keys.js
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
module.exports = Object.keys || function (obj) {
|
||||
var keys = [];
|
||||
for (var key in obj) keys.push(key);
|
||||
return keys;
|
||||
};
|
72
node_modules/dnode-protocol/lib/scrub.js
generated
vendored
Normal file
72
node_modules/dnode-protocol/lib/scrub.js
generated
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
var traverse = require('traverse');
|
||||
var objectKeys = require('./keys');
|
||||
var forEach = require('./foreach');
|
||||
|
||||
function indexOf (xs, x) {
|
||||
if (xs.indexOf) return xs.indexOf(x);
|
||||
for (var i = 0; i < xs.length; i++) if (xs[i] === x) return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// scrub callbacks out of requests in order to call them again later
|
||||
module.exports = function (callbacks) {
|
||||
return new Scrubber(callbacks);
|
||||
};
|
||||
|
||||
function Scrubber (callbacks) {
|
||||
this.callbacks = callbacks;
|
||||
}
|
||||
|
||||
// Take the functions out and note them for future use
|
||||
Scrubber.prototype.scrub = function (obj) {
|
||||
var self = this;
|
||||
var paths = {};
|
||||
var links = [];
|
||||
|
||||
var args = traverse(obj).map(function (node) {
|
||||
if (typeof node === 'function') {
|
||||
var i = indexOf(self.callbacks, node);
|
||||
if (i >= 0 && !(i in paths)) {
|
||||
// Keep previous function IDs only for the first function
|
||||
// found. This is somewhat suboptimal but the alternatives
|
||||
// are worse.
|
||||
paths[i] = this.path;
|
||||
}
|
||||
else {
|
||||
var id = self.callbacks.length;
|
||||
self.callbacks.push(node);
|
||||
paths[id] = this.path;
|
||||
}
|
||||
|
||||
this.update('[Function]');
|
||||
}
|
||||
else if (this.circular) {
|
||||
links.push({ from : this.circular.path, to : this.path });
|
||||
this.update('[Circular]');
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
arguments : args,
|
||||
callbacks : paths,
|
||||
links : links
|
||||
};
|
||||
};
|
||||
|
||||
// Replace callbacks. The supplied function should take a callback id and
|
||||
// return a callback of its own.
|
||||
Scrubber.prototype.unscrub = function (msg, f) {
|
||||
var args = msg.arguments || [];
|
||||
forEach(objectKeys(msg.callbacks || {}), function (sid) {
|
||||
var id = parseInt(sid, 10);
|
||||
var path = msg.callbacks[id];
|
||||
traverse.set(args, path, f(id));
|
||||
});
|
||||
|
||||
forEach(msg.links || [], function (link) {
|
||||
var value = traverse.get(args, link.from);
|
||||
traverse.set(args, link.to, value);
|
||||
});
|
||||
|
||||
return args;
|
||||
};
|
88
node_modules/dnode-protocol/package.json
generated
vendored
Normal file
88
node_modules/dnode-protocol/package.json
generated
vendored
Normal file
@@ -0,0 +1,88 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
{
|
||||
"name": "dnode-protocol",
|
||||
"raw": "dnode-protocol@~0.2.2",
|
||||
"rawSpec": "~0.2.2",
|
||||
"scope": null,
|
||||
"spec": ">=0.2.2 <0.3.0",
|
||||
"type": "range"
|
||||
},
|
||||
"/root/gitbook/node_modules/dnode"
|
||||
]
|
||||
],
|
||||
"_from": "dnode-protocol@>=0.2.2 <0.3.0",
|
||||
"_id": "dnode-protocol@0.2.2",
|
||||
"_inCache": true,
|
||||
"_installable": true,
|
||||
"_location": "/dnode-protocol",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"name": "dnode-protocol",
|
||||
"raw": "dnode-protocol@~0.2.2",
|
||||
"rawSpec": "~0.2.2",
|
||||
"scope": null,
|
||||
"spec": ">=0.2.2 <0.3.0",
|
||||
"type": "range"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/dnode"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/dnode-protocol/-/dnode-protocol-0.2.2.tgz",
|
||||
"_shasum": "51151d16fc3b5f84815ee0b9497a1061d0d1949d",
|
||||
"_shrinkwrap": null,
|
||||
"_spec": "dnode-protocol@~0.2.2",
|
||||
"_where": "/root/gitbook/node_modules/dnode",
|
||||
"author": {
|
||||
"email": "mail@substack.net",
|
||||
"name": "James Halliday",
|
||||
"url": "http://substack.net"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/substack/dnode-protocol/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"jsonify": "~0.0.0",
|
||||
"traverse": "~0.6.3"
|
||||
},
|
||||
"description": "implements the dnode protocol abstractly",
|
||||
"devDependencies": {
|
||||
"tap": "~0.2.5"
|
||||
},
|
||||
"directories": {},
|
||||
"dist": {
|
||||
"integrity": "sha512-QpT9Evvuky4kC/Ez0JjcrmcYu8b1fhB0Gh3wKm5/1YQckBS0IslPRayea6f9N7elUkIRbTAozQiuaX9E481Akw==",
|
||||
"shasum": "51151d16fc3b5f84815ee0b9497a1061d0d1949d",
|
||||
"signatures": [
|
||||
{
|
||||
"keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA",
|
||||
"sig": "MEQCIFgmp0psubqBePdPqAQPHsSLiRMu3vDnDVoeeckBasMzAiA8NRwjl/4y0J++98cJde+TXTDzRFb+YuTPqzyETRgjmQ=="
|
||||
}
|
||||
],
|
||||
"tarball": "https://registry.npmjs.org/dnode-protocol/-/dnode-protocol-0.2.2.tgz"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.4.0"
|
||||
},
|
||||
"homepage": "https://github.com/substack/dnode-protocol#readme",
|
||||
"license": "MIT",
|
||||
"main": "./index.js",
|
||||
"maintainers": [
|
||||
{
|
||||
"email": "mail@substack.net",
|
||||
"name": "substack"
|
||||
}
|
||||
],
|
||||
"name": "dnode-protocol",
|
||||
"optionalDependencies": {},
|
||||
"readme": "ERROR: No README data found!",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/substack/dnode-protocol.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "tap test/*.js"
|
||||
},
|
||||
"version": "0.2.2"
|
||||
}
|
22
node_modules/dnode-protocol/test/circular.js
generated
vendored
Normal file
22
node_modules/dnode-protocol/test/circular.js
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
var test;
|
||||
try { test = require('tap').test; }
|
||||
catch (e) { test = require('testling') }
|
||||
var Scrubber = require('../lib/scrub');
|
||||
|
||||
test('circular', function (t) {
|
||||
var s = new Scrubber;
|
||||
|
||||
var obj = { a : 1, b : 2 };
|
||||
obj.c = obj;
|
||||
|
||||
t.deepEqual(
|
||||
s.scrub([ obj ]),
|
||||
{
|
||||
arguments : [ { a : 1, b : 2, c : '[Circular]' } ],
|
||||
callbacks : {},
|
||||
links : [ { 'from' : [ '0' ], 'to' : [ '0', 'c' ] } ],
|
||||
}
|
||||
);
|
||||
|
||||
t.end();
|
||||
});
|
76
node_modules/dnode-protocol/test/fn.js
generated
vendored
Normal file
76
node_modules/dnode-protocol/test/fn.js
generated
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
var test;
|
||||
try { test = require('tap').test; }
|
||||
catch (e) { test = require('testling') }
|
||||
|
||||
var proto = require('../');
|
||||
var traverse = require('traverse');
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
|
||||
test('protoFn', function (t) {
|
||||
t.plan(7);
|
||||
|
||||
var s = proto(function (remote, conn) {
|
||||
t.ok(conn);
|
||||
|
||||
conn.on('ready', function () {
|
||||
t.deepEqual(remote, { a : 1, b : 2 });
|
||||
});
|
||||
|
||||
this.x = function (f, g) {
|
||||
setTimeout(f.bind({}, 7, 8, 9), 25);
|
||||
setTimeout(g.bind({}, [ 'q', 'r' ]), 50);
|
||||
};
|
||||
this.y = 555;
|
||||
});
|
||||
|
||||
var c = proto({ a : 1, b : 2 });
|
||||
|
||||
var sreqs = [];
|
||||
s.on('request', function (req) {
|
||||
sreqs.push(traverse.clone(req));
|
||||
c.handle(req);
|
||||
});
|
||||
|
||||
var creqs = [];
|
||||
c.on('request', function (req) {
|
||||
creqs.push(traverse.clone(req));
|
||||
s.handle(req);
|
||||
});
|
||||
|
||||
s.start();
|
||||
|
||||
t.deepEqual(sreqs, [ {
|
||||
method : 'methods',
|
||||
arguments : [ { x : '[Function]', y : 555 } ],
|
||||
callbacks : { 0 : [ '0', 'x' ] },
|
||||
links : []
|
||||
} ]);
|
||||
|
||||
c.start();
|
||||
|
||||
t.deepEqual(creqs, [ {
|
||||
method : 'methods',
|
||||
arguments : [ { a : 1, b : 2 } ],
|
||||
callbacks : {},
|
||||
links : []
|
||||
} ]);
|
||||
|
||||
var pending = 2;
|
||||
c.request('x', [
|
||||
function (x, y , z) {
|
||||
t.deepEqual([ x, y, z ], [ 7, 8, 9 ]);
|
||||
if (--pending === 0) t.end();
|
||||
},
|
||||
function (qr) {
|
||||
t.deepEqual(qr, [ 'q', 'r' ]);
|
||||
if (--pending === 0) t.end();
|
||||
}
|
||||
]);
|
||||
|
||||
t.deepEqual(creqs.slice(1), [ {
|
||||
method : 'x',
|
||||
arguments : [ '[Function]', '[Function]' ],
|
||||
callbacks : { 0 : [ '0' ], 1 : [ '1' ] },
|
||||
links : []
|
||||
} ]);
|
||||
});
|
66
node_modules/dnode-protocol/test/proto.js
generated
vendored
Normal file
66
node_modules/dnode-protocol/test/proto.js
generated
vendored
Normal file
@@ -0,0 +1,66 @@
|
||||
var test = require('tap').test;
|
||||
var proto = require('../');
|
||||
var traverse = require('traverse');
|
||||
|
||||
test('proto hashes', function (t) {
|
||||
t.plan(4);
|
||||
|
||||
var s = proto({
|
||||
x : function (f, g) {
|
||||
setTimeout(f.bind({}, 7, 8, 9), 25);
|
||||
setTimeout(g.bind({}, [ 'q', 'r' ]), 50);
|
||||
},
|
||||
y : 555
|
||||
});
|
||||
|
||||
var c = proto({});
|
||||
|
||||
var sreqs = [];
|
||||
s.on('request', function (req) {
|
||||
sreqs.push(traverse.clone(req));
|
||||
c.handle(req);
|
||||
});
|
||||
|
||||
var creqs = [];
|
||||
c.on('request', function (req) {
|
||||
creqs.push(traverse.clone(req));
|
||||
s.handle(req);
|
||||
});
|
||||
|
||||
s.start();
|
||||
|
||||
t.deepEqual(sreqs, [ {
|
||||
method : 'methods',
|
||||
arguments : [ { x : '[Function]', y : 555 } ],
|
||||
callbacks : { 0 : [ '0', 'x' ] },
|
||||
links : [],
|
||||
} ]);
|
||||
|
||||
c.start();
|
||||
|
||||
t.deepEqual(creqs, [ {
|
||||
method : 'methods',
|
||||
arguments : [ {} ],
|
||||
callbacks : {},
|
||||
links : [],
|
||||
} ]);
|
||||
|
||||
var pending = 2;
|
||||
c.request('x', [
|
||||
function (x, y , z) {
|
||||
t.deepEqual([ x, y, z ], [ 7, 8, 9 ]);
|
||||
if (--pending === 0) t.end();
|
||||
},
|
||||
function (qr) {
|
||||
t.deepEqual(qr, [ 'q', 'r' ]);
|
||||
if (--pending === 0) t.end();
|
||||
}
|
||||
]);
|
||||
|
||||
t.deepEqual(creqs.slice(1), [ {
|
||||
method : 'x',
|
||||
arguments : [ '[Function]', '[Function]' ],
|
||||
callbacks : { 0 : [ '0' ], 1 : [ '1' ] },
|
||||
links : [],
|
||||
} ]);
|
||||
});
|
141
node_modules/dnode-protocol/test/scrub.js
generated
vendored
Normal file
141
node_modules/dnode-protocol/test/scrub.js
generated
vendored
Normal file
@@ -0,0 +1,141 @@
|
||||
var test;
|
||||
try { test = require('tap').test; }
|
||||
catch (e) { test = require('testling') }
|
||||
var scrubber = require('../lib/scrub');
|
||||
|
||||
test('no functions', function (t) {
|
||||
var s = scrubber([]);
|
||||
t.deepEqual(
|
||||
s.scrub([ 1, 2, 3 ]),
|
||||
{
|
||||
arguments : [ 1, 2, 3 ],
|
||||
callbacks : {},
|
||||
links : [],
|
||||
}
|
||||
);
|
||||
|
||||
t.deepEqual(
|
||||
s.scrub([ 4, { a : 5, b : 6 } ]),
|
||||
{
|
||||
arguments : [ 4, { a : 5, b : 6 } ],
|
||||
callbacks : {},
|
||||
links : [],
|
||||
}
|
||||
);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('functions', function (t) {
|
||||
var s = scrubber([]);
|
||||
|
||||
var calls = { f : 0, g : 0 };
|
||||
var f = function () { calls.f ++ };
|
||||
var g = function () { calls.g ++ };
|
||||
|
||||
var sc = s.scrub([ 1, 2, f, g ]);
|
||||
t.deepEqual(sc, {
|
||||
arguments : [ 1, 2, '[Function]', '[Function]' ],
|
||||
callbacks : { 0 : [ '2' ], 1 : [ '3' ] },
|
||||
links : [],
|
||||
});
|
||||
|
||||
s.callbacks[0]();
|
||||
t.deepEqual(calls, { f : 1, g : 0 });
|
||||
|
||||
s.callbacks[1]();
|
||||
t.deepEqual(calls, { f : 1, g : 1 });
|
||||
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('link', function (t) {
|
||||
var s = scrubber([]);
|
||||
var x = [ [ 0, { a : 1, b : 2, c : 3 }, 4 ], 5, 6 ];
|
||||
x[0][1].d = x[0][1];
|
||||
var sc = s.scrub(x);
|
||||
|
||||
t.deepEqual(sc, {
|
||||
arguments : [
|
||||
[ 0, { a : 1, b : 2, c : 3, d : '[Circular]' }, 4 ], 5, 6
|
||||
],
|
||||
callbacks : {},
|
||||
links : [ { from : [ '0', '1' ], to : [ '0', '1', 'd' ] } ],
|
||||
});
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('multilink', function (t) {
|
||||
var s = scrubber([]);
|
||||
var x = [ [ 0, { a : 1, b : 2, c : 3 }, 4 ], 5, 6 ];
|
||||
x[0][1].d = x[0][1];
|
||||
x.push(x);
|
||||
var sc = s.scrub(x);
|
||||
|
||||
t.deepEqual(sc, {
|
||||
arguments : [
|
||||
[ 0, { a : 1, b : 2, c : 3, d : '[Circular]' }, 4 ],
|
||||
5, 6, '[Circular]'
|
||||
],
|
||||
callbacks : {},
|
||||
links : [
|
||||
{ from : [ '0', '1' ], to : [ '0', '1', 'd' ] },
|
||||
{ from : [], to : [ '3' ] },
|
||||
],
|
||||
});
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('enum set link', function (t) {
|
||||
var s = scrubber([]);
|
||||
var req = {
|
||||
method : 0,
|
||||
arguments : [ 33, '[Function]' ],
|
||||
callbacks : { 0 : [ '1' ] },
|
||||
links : [ {
|
||||
from : [ '0' ],
|
||||
to : [ '1', 'constructor', 'prototype', 'beep' ]
|
||||
} ]
|
||||
};
|
||||
|
||||
var args = s.unscrub(req, function (id) {
|
||||
return function () {};
|
||||
});
|
||||
t.ok(!(function () {}).beep, 'created non-enumerable property');
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('enum get link', function (t) {
|
||||
var s = scrubber([]);
|
||||
var req = {
|
||||
method : 0,
|
||||
arguments : [ 'doom', '[Function]' ],
|
||||
callbacks : { 0 : [ '1' ] },
|
||||
links : [ {
|
||||
from : [ '1', 'constructor', 'prototype', 'toString' ],
|
||||
to : [ '0' ]
|
||||
} ]
|
||||
};
|
||||
|
||||
var args = s.unscrub(req, function (id) {
|
||||
return function () {};
|
||||
});
|
||||
|
||||
t.ok(args[0] === undefined);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('skip set', function (t) {
|
||||
var s = scrubber([]);
|
||||
var req = {
|
||||
method : 0,
|
||||
arguments : [ { x : 33 }, '[Function]' ],
|
||||
callbacks : { 0 : [ '1' ] },
|
||||
links : [ { from : [ '0', 'x' ], to : [ '2' ] } ]
|
||||
};
|
||||
|
||||
var args = s.unscrub(req, function (id) {
|
||||
return function () {};
|
||||
});
|
||||
t.equal(args[2], 33);
|
||||
t.end();
|
||||
});
|
89
node_modules/dnode-protocol/test/wrap.js
generated
vendored
Normal file
89
node_modules/dnode-protocol/test/wrap.js
generated
vendored
Normal file
@@ -0,0 +1,89 @@
|
||||
var test = require('tap').test;
|
||||
var proto = require('../');
|
||||
var traverse = require('traverse');
|
||||
|
||||
test('proto hashes', function (t) {
|
||||
t.plan(10);
|
||||
var pending = 5;
|
||||
|
||||
var times = { s : 0, c : 0 };
|
||||
function done () {
|
||||
t.same(times.s, 2); // f, g
|
||||
t.same(times.c, 1); // x(f,g)
|
||||
t.end();
|
||||
}
|
||||
|
||||
function swrapper (fn) {
|
||||
// 1 of these
|
||||
t.equal(typeof fn, 'function');
|
||||
times.s ++;
|
||||
if (--pending === 0) done();
|
||||
return fn;
|
||||
}
|
||||
|
||||
function cwrapper (fn) {
|
||||
// 2 of these
|
||||
t.equal(typeof fn, 'function');
|
||||
times.c ++;
|
||||
if (--pending === 0) done();
|
||||
return fn;
|
||||
}
|
||||
|
||||
var s = proto({
|
||||
x : function (f, g) {
|
||||
setTimeout(f.bind({}, 7, 8, 9), 25);
|
||||
setTimeout(g.bind({}, [ 'q', 'r' ]), 50);
|
||||
},
|
||||
y : 555
|
||||
}, { wrap : swrapper });
|
||||
|
||||
var c = proto({}, { wrap : cwrapper });
|
||||
|
||||
var sreqs = [];
|
||||
s.on('request', function (req) {
|
||||
sreqs.push(traverse.clone(req));
|
||||
c.handle(req);
|
||||
});
|
||||
|
||||
var creqs = [];
|
||||
c.on('request', function (req) {
|
||||
creqs.push(traverse.clone(req));
|
||||
s.handle(req);
|
||||
});
|
||||
|
||||
s.start();
|
||||
|
||||
t.deepEqual(sreqs, [ {
|
||||
method : 'methods',
|
||||
arguments : [ { x : '[Function]', y : 555 } ],
|
||||
callbacks : { 0 : [ '0', 'x' ] },
|
||||
links : [],
|
||||
} ]);
|
||||
|
||||
c.start();
|
||||
|
||||
t.deepEqual(creqs, [ {
|
||||
method : 'methods',
|
||||
arguments : [ {} ],
|
||||
callbacks : {},
|
||||
links : [],
|
||||
} ]);
|
||||
|
||||
c.request('x', [
|
||||
function (x, y , z) {
|
||||
t.deepEqual([ x, y, z ], [ 7, 8, 9 ]);
|
||||
if (--pending === 0) done();
|
||||
},
|
||||
function (qr) {
|
||||
t.deepEqual(qr, [ 'q', 'r' ]);
|
||||
if (--pending === 0) done();
|
||||
}
|
||||
]);
|
||||
|
||||
t.deepEqual(creqs.slice(1), [ {
|
||||
method : 'x',
|
||||
arguments : [ '[Function]', '[Function]' ],
|
||||
callbacks : { 0 : [ '0' ], 1 : [ '1' ] },
|
||||
links : [],
|
||||
} ]);
|
||||
});
|
23
node_modules/dnode-protocol/testling/test.sh
generated
vendored
Normal file
23
node_modules/dnode-protocol/testling/test.sh
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
#!/bin/bash
|
||||
|
||||
if test -z "$user"; then
|
||||
echo -n "username: "
|
||||
read user
|
||||
fi
|
||||
|
||||
browsers=""
|
||||
if test -n "$2"; then
|
||||
browsers="browsers=$2"
|
||||
fi
|
||||
|
||||
function testFile {
|
||||
tar -cf- index.js "$1" node_modules/traverse/index.js \
|
||||
| curl -u "$user" -sSNT- \
|
||||
"http://testling.com/?$browsers&main=$1"
|
||||
}
|
||||
|
||||
if test -f "$1"; then
|
||||
testFile "$1"
|
||||
else
|
||||
echo not
|
||||
fi
|
Reference in New Issue
Block a user