feat: Add Be and tbd skill, also added Roadmap file

This commit is contained in:
2026-05-10 16:32:12 -04:00
parent 3500ade13f
commit 0bb8885802
29587 changed files with 10611695 additions and 0 deletions

2
Skills/@be/node_modules/syslog2-pure-js/.npmignore generated vendored Normal file
View File

@@ -0,0 +1,2 @@
/node_modules
/coverage

325
Skills/@be/node_modules/syslog2-pure-js/README.md generated vendored Normal file
View File

@@ -0,0 +1,325 @@
# Syslog2
This module presents as a Node (streams2) writable stream, and outputs to
Syslog. It supports structured data and minor interruption recovery (it will
try a couple times to reconnect if your connection is dumped). It is written in
pure Javascript, no native bindings. Kris Reeves wrote it because the available
modules that he could find were basic, with poor tests, or otherwise lacking,
and it didn't seem that there was anything available written to the full
RFC 5424 specification.
Tim Garthwaite forked Kris's original implementation to remove Unix socket
support, so that there really are no native bindings. This is useful when
you'd like to do an install on one platform, but publish to another, for
instance when developing on Mac but delivering on an embedded Linux system.
# Usage
var Syslog = require('syslog2-pure-js');
var log = Syslog.create();
log.write('message');
`Syslog.create(options, callback)` is a shortcut for `new Syslog(options)`
followed by `.connect(callback)`.
# Options
Various options are supported in the constructor/`.create` method:
new Syslog({
decodeBuffers: <boolean>,
decodeStrings: <boolean>,
useStructuredData: <boolean>,
defaultSeverity: <string>,
PEN: <integer>,
type: <string>,
facility: <string>,
{host|hostname}: <string>,
{name|appName}: <string>,
{msgId|msgID}: <string>,
pid: <integer>,
connection: {
type: {tcp|udp|stream},
host: <adress>,
port: <port>,
stream: <node stream>
},
reconnect: {
enabled: {true|false},
maxTries: <integer>,
initialDelay: <milliseconds>,
delayFactor: <number>,
maxDelay: <milliseconds>
}
})
### Connection
This is an object specifying connection details. All keys are optional. If you do not specify 'type', it will be inferred from other keys provided (if `stream` exists, it assumes a stream; otherwise it assumes UDP).
new Syslog({
connection: {
type: {tcp|udp|stream},
host: <adress>,
port: <port>,
stream: <node stream>
}
});
Defaults are:
- type: `udp`
- host: `127.0.0.1`
- port: `514`
### Reconnect
Controls the reconnect behavior. All keys are optional.
- enabled: Whether to enable auto reconnect. Default: false
- maxTries: How many times to attempt to reconnect. Default: Infinity
- initialDelay: How long to wait before attempting to reconnect, first try. Default: 100
- delayFactor: How much to increase the retry delay after each attempt; this value is *multiplied* against the current delay. Default: 1.2
- maxDelay: The maximum value the retry delay can have. Default: 30000
### Syslog-specific keys
All keys other than `connection` and `reconnect` are passed along to [syslog-streams2](https://www.npmjs.com/package/syslog-streams2). That documentation is included here for convenience, but be aware that changes there supersede anything written here.
The first set of options apply to the stream itself and how it handles incoming data. The second set of options are curried into the glossy instance that performs the translation.
### decodeBuffers
True to decode buffers written to the stream; false to do nothing. You should be writing objects to the stream, but it could be handy when piping from other locations. Defaults to false.
### decodeJSON
True to attempt to decode strings as JSON; false to do nothing. May be used in conjunction with decodeBuffers. Defaults to false.
### useStructuredData
True to attempt to encode structured data; false to do nothing. Defaults to true unless 'type' is set (more on that below).
### defaultSeverity
The default severity of a log message, if not specified. This is used for all messages interpreted as strings or invalid bunyan/glossy records, and bunyan or glossy records that do not specify a level/severity.
### PEN
If you have a Private Enterprise Number, specify it here. Non-standardized structured data is tagged with your PEN. To strictly conform to the spec, you should not use this unless you have registered a PEN with IANA.
### type
This is passed along to glossy to specify what type of output to create. Right now, 'BSD' is the only valid option, to be used if you want to output 'old style' RFC3164-compatible messages. Leave empty for RFC5424-style messages. Glossy's documentation mentions RFC 5848, but no references currently exist in the code, so these are the only two options.
### facility
The facility to log to. Case insensitive. Defaults to `local0`. Can be overridden in `.write()`.
Valid facilities are:
KERN - Kernel messages
USER - User-level messages
MAIL - Mail system
DAEMON - System daemons
AUTH - Security/authorization messages
SYSLOG - Messages generated internally by syslogd
LPR - Line printer subsystem
NEWS - Network news subsystem
UUCP - UUCP subsystem
CLOCK - Clock daemon
SEC - Security/authorization messages
FTP - FTP daemon
NTP - NTP subsystem
AUDIT - Log audit
ALERT - Log alert
LOCAL0 - Local use 0
LOCAL1 - Local use 1
LOCAL2 - Local use 2
LOCAL3 - Local use 3
LOCAL4 - Local use 4
LOCAL5 - Local use 5
LOCAL6 - Local use 6
LOCAL7 - Local use 7
### host / hostname
The hostname of the system generating the log message. Defaults to `os.hostname()`, falls back on the nil value(`-`). Can be overriden in `.write()`.
From RFC5424:
The HOSTNAME field SHOULD contain the hostname and the domain name of
the originator in the format specified in STD 13 [RFC1034]. This
format is called a Fully Qualified Domain Name (FQDN) in this
document.
In practice, not all syslog applications are able to provide an FQDN.
As such, other values MAY also be present in HOSTNAME. This document
makes provisions for using other values in such situations. A syslog
application SHOULD provide the most specific available value first.
The order of preference for the contents of the HOSTNAME field is as
follows:
1. FQDN
2. Static IP address
3. hostname
4. Dynamic IP address
5. the NILVALUE
### pid
The process id of the process generating the log message. Defaults to `process.pid`, falls back on the nil value(`-`). Can be overridden in `.write()`.
### name / appName
The app name to use when logging messages. Defaults to `process.title`, falls back on `process.argv[0]` followed by the nil value(`-`). Can be overriden in `.write()`.
The APP-NAME field SHOULD identify the device or application that
originated the message. It is a string without further semantics.
It is intended for filtering messages on a relay or collector.
### msgId / msgID
The message id to use when logging messages. Defaults to the nil value. Can be overriden in `.write()`.
The MSGID SHOULD identify the type of message. For example, a
firewall might use the MSGID "TCPIN" for incoming TCP traffic and the
MSGID "TCPOUT" for outgoing TCP traffic. Messages with the same
MSGID should reflect events of the same semantics. The MSGID itself
is a string without further semantics. It is intended for filtering
messages on a relay or collector.
# syslog.connect()
If you've created an instance with the constructor, you'll need to connect it. Do that with `syslog.connect()`. If you supply a callback, it will be called on connection, or with an error if there was an error. **The callback may be called multiple times** since Syslog performs auto-reconnect. It's recommended that you use events instead. In fact, it's recommended that you just use `Syslog.create()` rather than `new Syslog()`.
# Event: 'connect'
Emitted each time Syslog2 establishes a connection.
# Event: 'error'
Emitted when Syslog2 is unable to establish an initial connection, or when a connection is lost and Syslog2 is unable to reconnect.
# Event: 'warn'
Emitted each time Syslog2 loses connection, before retrying. If retries are disabled or fail, an `error` event will also be emitted.
# syslog.write()
Data is handled slightly differently based on the input. Bunyan-style records are identified by the presence of a `msg` key and validated against Bunyan's record format. Glossy-style records are identified by the presence of a `message` key and validated against Glossy's record format.
Records that fail validation, or that return `false` when run through Glossy will be converted to JSON and written as a plain string.
### Plain string
`syslog.write('foo')`
This will generate the header field according to the options created on instantiation and append the specified message. Example:
`<149>1 2014-12-05T22:44:25.863Z myndzi node 20308 - foo`
### Plain object
This module makes use of [syslog-streams2](https://www.npmjs.com/package/syslog-streams2) to process messages from objects into the RFC5424 Syslog format. You can write a [Bunyan](https://www.npmjs.com/package/bunyan) record, a [Glossy](https://www.npmjs.com/package/glossy) record, or an arbitrary object, with the Bunyan format being preferred.
#### Bunyan record
Typically, you would use the bunyan module to write data to the stream, but if you write data that validates against a Bunyan record, it will be interpreted as such. Bunyan records look like this:
{
v: <version>,
level: <log level>,
name: <originating application name>,
hostname: <originating hostname>,
pid: <originating process id>,
time: <timestamp>,
msg: <log message>
}
- v: Supplied by Bunyan. The version number of the record schema
- level: the log level to use. You may specify a numerical value from 0-100 or a Bunyan log level string ('fatal', 'error', 'warn', 'info', 'debug', 'trace'). Case insensitive. Left empty, it will default to the syslog 'notice' level.
- name: A string; defaults to the instantiated value
- hostname: A string; defaults to the instantiated value
- pid: The originating proccess ID. Left empty, will use the value of `process.pid` or the nil value if unavailable.
- time: the timestamp to use. You may specify a Javascript Date object or any string that can be converted to one. (*Note: Javascript will convert strings in local system time if they do not contain timestamp information*) Left empty, it will default to the current timestamp.
- msg: the message you want to log. Any extra keys not processed into structured data will be appended to this message as JSON.
Extra keys are added directly to the Bunyan object.
#### Glossy record
Glossy records look like this:
{
appName: <originating application name>,
date: <timestamp>,
facility: <facility>,
host: <originating hostname>,
severity: <severity>,
pid: <originating process id>,
message: <log message>,
structuredData: <structured data>
}
- appName: A string; defaults to the instantiated value
- date: the timestamp to use. You may specify a Javascript Date object or any string that can be converted to one. (*Note: Javascript will convert strings in local system time if they do not contain timestamp information*) Left empty, it will default to the current timestamp.
- facility: a syslog *facility* identifier, as above; Defaults to the instantiated value.
- hostname: A string; defaults to the instantiated value
- level: the log level to use. You may specify a numerical value from 0-100 or a Bunyan log level string ('fatal', 'error', 'warn', 'info', 'debug', 'trace'). Case insensitive. Left empty, it will default to the syslog 'notice' level.
- message: the message you want to log. Any extra keys not processed into structured data will be appended to this message as JSON.
- msgId: A string; defaults to the instantiated value
- pid: The originating proccess ID. Left empty, will use the value of `process.pid` or the nil value if unavailable.
- severity: a syslog *severity* identifier
### Misc. unlikelihoods
Undefined and null are ignored completely. Dates are converted to a string using the `.toISOString()` method. Arrays are processed into JSON strings.
### Extra keys
Any extra keys passed on an object will first be converted to structured data if possible; any keys remaining after conversion will be processed into JSON strings and appended to the log message (if any). Example:
`log.write({ foo: 'bar' });`
Outputs:
`<149>1 2014-12-05T22:58:07.725Z myndzi node 20428 - hello {"foo":"bar"}`
# Structured data
### From Bunyan records
When possible, extra object keys will be processed into structured data. There are two cases where this will happen.
- When you provide a key matching a defined SDID in the RFC, such as 'timeQuality', 'origin', or 'meta'
- When you provide a PEN
**Note:** Object properties that do not contain objects cannot be converted to structured data (e.g. `{ custom: 'foo', msg: 'hello' }`; neither can properties with keys that violate the acceptable characters for an SDID, e.g. `{ 'foo@bar': 'baz', msg: 'hello' }`.
Standardized SDIDs will be validated and converted. Any remaining keys will be treated as custom structured data and formatted with your PEN.
Example:
`log.write({ meta: { ip: '127.1.1.1' }, msg: 'hello' })`
outputs:
`<149>1 2014-12-05T23:01:36.170Z myndzi node 20465 - [meta ip="127.1.1.1"] hello`
while
`log.write({ custom: { key: 'val' }, msg: 'hello' })`
outputs:
`<149>1 2014-12-05T23:03:58.957Z myndzi node 20492 - [custom@32473 key="val"] hello`
### From Glossy records
In general, the same as above, with the exception that glossy's format makes structured data explicit in the `structuredData` key, so no "implying" is done by exclusion in the way that it is done for Bunyan.
# Using with Bunyan
Syslog2 was designed for use with [bunyan](https://npmjs.com/package/bunyan). It can be used like so:
var log = bunyan.createLogger({
name: 'myapp',
stream: {
type: 'raw',
level: 'debug',
stream: Syslog.create(/* opts */)
}
})
# Testing
Clone the repository and run `npm test`

174
Skills/@be/node_modules/syslog2-pure-js/index.js generated vendored Normal file
View File

@@ -0,0 +1,174 @@
'use strict';
var PassThrough = require('stream').PassThrough,
inherits = require('util').inherits;
var SyslogStream = require('syslog-streams2'),
UdpStream = require('udp-streams2'),
TcpStream = require('net').Socket;
var clone = require('clone');
function Syslog(opts) {
PassThrough.call(this, { objectMode: true });
this.retrying = false;
this.shuttingDown = false;
this.pause();
Syslog.parseArgs.call(this, opts);
};
inherits(Syslog, PassThrough);
Syslog.create = function (opts, cb) {
if (typeof opts === 'function') {
cb = opts;
opts = null;
}
var stream = new Syslog(opts);
stream.connect(cb);
return stream;
};
Syslog.parseArgs = function (opts) {
opts = clone(opts || { });
var conn = opts.connection || { };
delete opts.connection;
// for tcp/udp sockets
this.host = conn.host || '127.0.0.1';
this.port = conn.port || 514;
this.type = conn.type || 'udp';
this.syslog = new SyslogStream(opts);
this.stream = null;
this.pipe(this.syslog);
var recon = (opts.reconnect && typeof opts.reconnect === 'object') ? opts.reconnect : { };
delete opts.reconnect;
var num;
if (!recon.hasOwnProperty('enabled')) { recon.enabled = false; }
num = parseInt(recon.maxTries, 10);
recon.maxTries = !isNaN(num) ? num : Infinity;
num = parseInt(recon.initialDelay, 10);
recon.initialDelay = !isNaN(num) ? num : 100;
num = parseInt(recon.delayFactor, 10);
recon.delayFactor = !isNaN(num) ? num : 1.2;
num = parseInt(recon.maxDelay, 10);
recon.maxDelay = !isNaN(num) ? num : 30*1000;
this.reconnect = recon;
};
Syslog.prototype.end = function () {
this.shuttingDown = true;
Syslog.super_.prototype.end.apply(this, arguments);
};
Syslog.prototype.connect = function (cb) {
var self = this;
switch (self.type) {
case 'tcp':
self.stream = new TcpStream();
self.stream.connect(self.port, self.host);
break;
case 'udp':
self.stream = new UdpStream();
self.stream.connect(self.port, self.host);
break;
default:
cb(new Error('Unsupported transport type: ' + self.type));
break;
}
var onConnect, onClose, onError, cleanup;
var connected = false;
onConnect = function () {
connected = true;
self.syslog.pipe(self.stream);
self.resume();
if (typeof cb === 'function') { cb(); }
else { self.emit('connect'); }
};
onClose = function () {
cleanup();
};
onError = function (err) {
// if it was a connection error, trigger the callback
if (!connected && typeof cb === 'function') {
cb(err);
}
self.emit('warn', err);
cleanup();
};
cleanup = function () {
self.pause();
self.unpipe(self.stream);
self.stream.removeListener('error', onError);
self.stream.removeListener('connect', onConnect);
self.stream.removeListener('close', onClose);
self.stream = null;
self.maybeReconnect();
};
// each stream only errors once, so we use '.once' instead of '.on' here
// even though we ourselves may emit multiple errors
self.stream.once('error', onError);
self.stream.once('connect', onConnect);
self.stream.once('close', onClose);
return self;
};
Syslog.prototype.maybeReconnect = function () {
var self = this;
if (self.stream) { return; }
if (self.retrying || self.shuttingDown) { return; }
var recon = self.reconnect;
if (!recon.enabled) {
self.emit('error', new Error('Disconnected, reconnect disabled'));
return;
}
(function retry(n, dly) {
self.retrying = true;
if (self.shuttingDown) { return; }
if (n >= recon.maxTries) {
self.emit('error', new Error('Unable to reconnect, reached max retries'));
return;
}
setTimeout(function () {
self.connect(function (err) {
if (err) {
return retry(n+1, Math.min(recon.maxDelay, dly * recon.delayFactor));
}
self.retrying = false;
});
}, dly);
})(0, recon.initialDelay);
};
module.exports = Syslog;

View File

@@ -0,0 +1 @@
node_modules/

View File

@@ -0,0 +1,5 @@
language: node_js
node_js:
- 0.6
- 0.8
- 0.10

View File

@@ -0,0 +1,18 @@
Copyright © 2011-2014 Paul Vorbach <paul@vorba.ch>
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, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -0,0 +1,126 @@
# clone
[![build status](https://secure.travis-ci.org/pvorb/node-clone.png)](http://travis-ci.org/pvorb/node-clone)
offers foolproof _deep cloning_ of variables in JavaScript.
## Installation
npm install clone
or
ender build clone
## Example
~~~ javascript
var clone = require('clone');
var a, b;
a = { foo: { bar: 'baz' } }; // initial value of a
b = clone(a); // clone a -> b
a.foo.bar = 'foo'; // change a
console.log(a); // show a
console.log(b); // show b
~~~
This will print:
~~~ javascript
{ foo: { bar: 'foo' } }
{ foo: { bar: 'baz' } }
~~~
**clone** masters cloning simple objects (even with custom prototype), arrays,
Date objects, and RegExp objects. Everything is cloned recursively, so that you
can clone dates in arrays in objects, for example.
## API
`clone(val, circular, depth)`
* `val` -- the value that you want to clone, any type allowed
* `circular` -- boolean
Call `clone` with `circular` set to `false` if you are certain that `obj`
contains no circular references. This will give better performance if needed.
There is no error if `undefined` or `null` is passed as `obj`.
* `depth` -- depth to which the object is to be cloned (optional,
defaults to infinity)
`clone.clonePrototype(obj)`
* `obj` -- the object that you want to clone
Does a prototype clone as
[described by Oran Looney](http://oranlooney.com/functional-javascript/).
## Circular References
~~~ javascript
var a, b;
a = { hello: 'world' };
a.myself = a;
b = clone(a);
console.log(b);
~~~
This will print:
~~~ javascript
{ hello: "world", myself: [Circular] }
~~~
So, `b.myself` points to `b`, not `a`. Neat!
## Test
npm test
## Caveat
Some special objects like a socket or `process.stdout`/`stderr` are known to not
be cloneable. If you find other objects that cannot be cloned, please [open an
issue](https://github.com/pvorb/node-clone/issues/new).
## Bugs and Issues
If you encounter any bugs or issues, feel free to [open an issue at
github](https://github.com/pvorb/node-clone/issues) or send me an email to
<paul@vorba.ch>. I also always like to hear from you, if youre using my code.
## License
Copyright © 2011-2014 [Paul Vorbach](http://paul.vorba.ch/) and
[contributors](https://github.com/pvorb/node-clone/graphs/contributors).
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, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -0,0 +1,144 @@
'use strict';
function objectToString(o) {
return Object.prototype.toString.call(o);
}
// shim for Node's 'util' package
// DO NOT REMOVE THIS! It is required for compatibility with EnderJS (http://enderjs.com/).
var util = {
isArray: function (ar) {
return Array.isArray(ar) || (typeof ar === 'object' && objectToString(ar) === '[object Array]');
},
isDate: function (d) {
return typeof d === 'object' && objectToString(d) === '[object Date]';
},
isRegExp: function (re) {
return typeof re === 'object' && objectToString(re) === '[object RegExp]';
},
getRegExpFlags: function (re) {
var flags = '';
re.global && (flags += 'g');
re.ignoreCase && (flags += 'i');
re.multiline && (flags += 'm');
return flags;
}
};
if (typeof module === 'object')
module.exports = clone;
/**
* Clones (copies) an Object using deep copying.
*
* This function supports circular references by default, but if you are certain
* there are no circular references in your object, you can save some CPU time
* by calling clone(obj, false).
*
* Caution: if `circular` is false and `parent` contains circular references,
* your program may enter an infinite loop and crash.
*
* @param `parent` - the object to be cloned
* @param `circular` - set to true if the object to be cloned may contain
* circular references. (optional - true by default)
* @param `depth` - set to a number if the object is only to be cloned to
* a particular depth. (optional - defaults to Infinity)
* @param `prototype` - sets the prototype to be used when cloning an object.
* (optional - defaults to parent prototype).
*/
function clone(parent, circular, depth, prototype) {
// maintain two arrays for circular references, where corresponding parents
// and children have the same index
var allParents = [];
var allChildren = [];
var useBuffer = typeof Buffer != 'undefined';
if (typeof circular == 'undefined')
circular = true;
if (typeof depth == 'undefined')
depth = Infinity;
// recurse this function so we don't reset allParents and allChildren
function _clone(parent, depth) {
// cloning null always returns null
if (parent === null)
return null;
if (depth == 0)
return parent;
var child;
var proto;
if (typeof parent != 'object') {
return parent;
}
if (util.isArray(parent)) {
child = [];
} else if (util.isRegExp(parent)) {
child = new RegExp(parent.source, util.getRegExpFlags(parent));
if (parent.lastIndex) child.lastIndex = parent.lastIndex;
} else if (util.isDate(parent)) {
child = new Date(parent.getTime());
} else if (useBuffer && Buffer.isBuffer(parent)) {
child = new Buffer(parent.length);
parent.copy(child);
return child;
} else {
if (typeof prototype == 'undefined') {
proto = Object.getPrototypeOf(parent);
child = Object.create(proto);
}
else {
child = Object.create(prototype);
proto = prototype;
}
}
if (circular) {
var index = allParents.indexOf(parent);
if (index != -1) {
return allChildren[index];
}
allParents.push(parent);
allChildren.push(child);
}
for (var i in parent) {
var attrs;
if (proto) {
attrs = Object.getOwnPropertyDescriptor(proto, i);
}
if (attrs && attrs.set == null) {
continue;
}
child[i] = _clone(parent[i], depth - 1);
}
return child;
}
return _clone(parent, depth);
}
/**
* Simple flat clone using prototype, accepts only objects, usefull for property
* override on FLAT configuration object (no nested props).
*
* USE WITH CAUTION! This may not behave as you wish if you do not know how this
* works.
*/
clone.clonePrototype = function(parent) {
if (parent === null)
return null;
var c = function () {};
c.prototype = parent;
return new c();
};

View File

@@ -0,0 +1,50 @@
{
"name": "clone",
"description": "deep cloning of objects and arrays",
"tags": [
"clone",
"object",
"array",
"function",
"date"
],
"version": "0.2.0",
"repository": {
"type": "git",
"url": "git://github.com/pvorb/node-clone.git"
},
"bugs": {
"url": "https://github.com/pvorb/node-clone/issues"
},
"main": "clone.js",
"author": "Paul Vorbach <paul@vorba.ch> (http://paul.vorba.ch/)",
"contributors": [
"Blake Miner <miner.blake@gmail.com> (http://www.blakeminer.com/)",
"Tian You <axqd001@gmail.com> (http://blog.axqd.net/)",
"George Stagas <gstagas@gmail.com> (http://stagas.com/)",
"Tobiasz Cudnik <tobiasz.cudnik@gmail.com> (https://github.com/TobiaszCudnik)",
"Pavel Lang <langpavel@phpskelet.org> (https://github.com/langpavel)",
"Dan MacTough (http://yabfog.com/)",
"w1nk (https://github.com/w1nk)",
"Hugh Kennedy (http://twitter.com/hughskennedy)",
"Dustin Diaz (http://dustindiaz.com)",
"Ilya Shaisultanov (https://github.com/diversario)",
"Nathan MacInnes <nathan@macinn.es> (http://macinn.es/)",
"Benjamin E. Coe <ben@npmjs.com> (https://twitter.com/benjamincoe)",
"Nathan Zadoks (https://github.com/nathan7)",
"Róbert Oroszi <robert+gh@oroszi.net> (https://github.com/oroce)"
],
"license": "MIT",
"engines": {
"node": "*"
},
"dependencies": {},
"devDependencies": {
"underscore": "*",
"nodeunit": "*"
},
"optionalDependencies": {},
"scripts": {
"test": "nodeunit test.js"
}
}

View File

@@ -0,0 +1,289 @@
if(module.parent === null) {
console.log('Run this test file with nodeunit:');
console.log('$ nodeunit test.js');
}
var clone = require('./');
var util = require('util');
var _ = require('underscore');
exports["clone string"] = function(test) {
test.expect(2); // how many tests?
var a = "foo";
test.strictEqual(clone(a), a);
a = "";
test.strictEqual(clone(a), a);
test.done();
};
exports["clone number"] = function(test) {
test.expect(5); // how many tests?
var a = 0;
test.strictEqual(clone(a), a);
a = 1;
test.strictEqual(clone(a), a);
a = -1000;
test.strictEqual(clone(a), a);
a = 3.1415927;
test.strictEqual(clone(a), a);
a = -3.1415927;
test.strictEqual(clone(a), a);
test.done();
};
exports["clone date"] = function(test) {
test.expect(3); // how many tests?
var a = new Date;
var c = clone(a);
test.ok(a instanceof Date);
test.ok(c instanceof Date);
test.equal(c.getTime(), a.getTime());
test.done();
};
exports["clone object"] = function(test) {
test.expect(2); // how many tests?
var a = { foo: { bar: "baz" } };
var b = clone(a);
test.ok(_(a).isEqual(b), "underscore equal");
test.deepEqual(b, a);
test.done();
};
exports["clone array"] = function(test) {
test.expect(2); // how many tests?
var a = [
{ foo: "bar" },
"baz"
];
var b = clone(a);
test.ok(_(a).isEqual(b), "underscore equal");
test.deepEqual(b, a);
test.done();
};
exports["clone buffer"] = function(test) {
test.expect(1);
var a = new Buffer("this is a test buffer");
var b = clone(a);
// no underscore equal since it has no concept of Buffers
test.deepEqual(b, a);
test.done();
};
exports["clone regexp"] = function(test) {
test.expect(5);
var a = /abc123/gi;
var b = clone(a);
test.deepEqual(b, a);
var c = /a/g;
test.ok(c.lastIndex === 0);
c.exec('123a456a');
test.ok(c.lastIndex === 4);
var d = clone(c);
test.ok(d.global);
test.ok(d.lastIndex === 4);
test.done();
};
exports["clone object containing array"] = function(test) {
test.expect(2); // how many tests?
var a = {
arr1: [ { a: '1234', b: '2345' } ],
arr2: [ { c: '345', d: '456' } ]
};
var b = clone(a);
test.ok(_(a).isEqual(b), "underscore equal");
test.deepEqual(b, a);
test.done();
};
exports["clone object with circular reference"] = function(test) {
test.expect(8); // how many tests?
var _ = test.ok;
var c = [1, "foo", {'hello': 'bar'}, function() {}, false, [2]];
var b = [c, 2, 3, 4];
var a = {'b': b, 'c': c};
a.loop = a;
a.loop2 = a;
c.loop = c;
c.aloop = a;
var aCopy = clone(a);
_(a != aCopy);
_(a.c != aCopy.c);
_(aCopy.c == aCopy.b[0]);
_(aCopy.c.loop.loop.aloop == aCopy);
_(aCopy.c[0] == a.c[0]);
//console.log(util.inspect(aCopy, true, null) );
//console.log("------------------------------------------------------------");
//console.log(util.inspect(a, true, null) );
_(eq(a, aCopy));
aCopy.c[0] = 2;
_(!eq(a, aCopy));
aCopy.c = "2";
_(!eq(a, aCopy));
//console.log("------------------------------------------------------------");
//console.log(util.inspect(aCopy, true, null) );
function eq(x, y) {
return util.inspect(x, true, null) === util.inspect(y, true, null);
}
test.done();
};
exports['clonePrototype'] = function(test) {
test.expect(3); // how many tests?
var a = {
a: "aaa",
x: 123,
y: 45.65
};
var b = clone.clonePrototype(a);
test.strictEqual(b.a, a.a);
test.strictEqual(b.x, a.x);
test.strictEqual(b.y, a.y);
test.done();
}
exports['cloneWithinNewVMContext'] = function(test) {
test.expect(3);
var vm = require('vm');
var ctx = vm.createContext({ clone: clone });
var script = "clone( {array: [1, 2, 3], date: new Date(), regex: /^foo$/ig} );";
var results = vm.runInContext(script, ctx);
test.ok(results.array instanceof Array);
test.ok(results.date instanceof Date);
test.ok(results.regex instanceof RegExp);
test.done();
}
exports['cloneObjectWithNoConstructor'] = function(test) {
test.expect(3);
var n = null;
var a = { foo: 'bar' };
a.__proto__ = n;
test.ok(typeof a === 'object');
test.ok(typeof a !== null);
var b = clone(a);
test.ok(a.foo, b.foo);
test.done();
}
exports['clone object with depth argument'] = function (test) {
test.expect(6);
var a = {
foo: {
bar : {
baz : 'qux'
}
}
};
var b = clone(a, false, 1);
test.deepEqual(b, a);
test.notEqual(b, a);
test.strictEqual(b.foo, a.foo);
b = clone(a, true, 2);
test.deepEqual(b, a);
test.notEqual(b.foo, a.foo);
test.strictEqual(b.foo.bar, a.foo.bar);
test.done();
}
exports['maintain prototype chain in clones'] = function (test) {
test.expect(1);
function Constructor() {}
var a = new Constructor();
var b = clone(a);
test.strictEqual(Object.getPrototypeOf(a), Object.getPrototypeOf(b));
test.done();
}
exports['parent prototype is overriden with prototype provided'] = function (test) {
test.expect(1);
function Constructor() {}
var a = new Constructor();
var b = clone(a, true, Infinity, null);
test.strictEqual(b.__defineSetter__, undefined);
test.done();
}
exports['clone object with null children'] = function(test) {
test.expect(1);
var a = {
foo: {
bar: null,
baz: {
qux: false
}
}
};
var b = clone(a);
test.deepEqual(b, a);
test.done();
}
exports['clone instance with getter'] = function(test) {
test.expect(1);
function Ctor() {};
Object.defineProperty(Ctor.prototype, 'prop', {
configurable: true,
enumerable: true,
get: function() {
return 'value';
}
});
var a = new Ctor();
var b = clone(a);
test.strictEqual(b.prop, 'value');
test.done();
};

31
Skills/@be/node_modules/syslog2-pure-js/package.json generated vendored Normal file
View File

@@ -0,0 +1,31 @@
{
"name": "syslog2-pure-js",
"version": "1.0.1",
"description": "Multi-transport Syslog stream with reconnect, forked from syslog2 by Kris Reeves, with Unix sockets support removed",
"repository": {
"type": "git",
"url": "https://github.com/mividtim/syslog2"
},
"main": "./index.js",
"dependencies": {
"clone": "^0.2.0",
"syslog-streams2": "^1.0.1",
"udp-streams2": "^1.0.6"
},
"devDependencies": {
"mocha": "^2.0.1",
"should": "^4.3.0"
},
"scripts": {
"test": "mocha -u bdd -R spec test.js"
},
"keywords": [
"bunyan",
"syslog",
"stream",
"streams2"
],
"author": "Kris Reeves",
"maintainer": "Tim Garthwaite <tim@mividstudios.com>",
"license": "ISC"
}

227
Skills/@be/node_modules/syslog2-pure-js/test.js generated vendored Normal file
View File

@@ -0,0 +1,227 @@
'use strict';
var Syslog = require('./index'),
fs = require('fs'),
net = require('net'),
dgram = require('dgram');
var BIND_PORT = 1234,
SOCKET_FILE = '/tmp/syslog2-test';
require('should');
function unlink(done) {
fs.unlink(SOCKET_FILE, done.bind(null, null));
}
before(unlink);
after(unlink);
// these are more thoroughly tested in their respective modules; just making sure
// that the logic to hook them up works correctly
describe('Transports', function () {
describe('tcp', function () {
var server;
before(function (done) {
server = net.createServer();
server.listen(BIND_PORT, done);
});
after(function (done) {
server.close(done);
});
it('should connect and pass messages', function (done) {
var log = new Syslog({
connection: {
type: 'tcp',
host: '127.0.0.1',
port: BIND_PORT
}
});
server.once('connection', function (socket) {
socket.once('data', function (chunk) {
log.end(done);
});
});
log.connect(function () {
log.write({msg: 'hello'});
});
});
});
describe('udp', function () {
var server;
before(function (done) {
server = dgram.createSocket('udp4');
server.bind(BIND_PORT, done);
});
after(function () {
server.close();
});
it('should pass messages', function (done) {
var log = new Syslog({
connection: {
type: 'udp',
host: '127.0.0.1',
port: BIND_PORT
}
});
server.once('message', function (chunk) {
log.end(done);
});
log.connect(function () {
log.write({msg: 'hello'});
});
});
});
});
describe('Syslog2', function () {
var server;
beforeEach(function (done) {
server = net.createServer();
server.listen(BIND_PORT, done);
});
afterEach(function (done) {
server.close(done);
});
it('should default to not reconnecting', function (done) {
var log = new Syslog({
connection: {
type: 'tcp',
port: BIND_PORT
}
});
server.once('connection', function (socket) {
socket.destroy();
});
log.connect(function () {
log.once('error', function (err) {
err.message.should.match(/Disconnected, reconnect disabled/);
log.end(done);
});
});
});
it('should emit a \'warn\' event for socket errors while reconnecting', function (done) {
var log = new Syslog({
connection: {
type: 'tcp',
port: BIND_PORT
}, reconnect: {
enabled: true,
maxTries: 1,
initalDelay: 0,
delayFactor: 0,
maxDelay: 0
}
});
server.once('connection', function (socket) {
log.stream.emit('error', 'foo');
socket.destroy();
});
log.connect(function () {
log.once('warn', function (err) {
err.should.equal('foo');
log.end(done);
});
});
});
it('should give up after the specified number of reconnection attempts', function (done) {
var log = new Syslog({
connection: {
type: 'tcp',
ip: '127.0.0.1',
port: 64993
}, reconnect: {
enabled: true,
maxTries: 1,
initalDelay: 0,
delayFactor: 0,
maxDelay: 0
}
});
server.once('connection', function (socket) {
socket.destroy();
});
log.connect(function () {
log.once('error', function (err) {
err.should.match(/Unable to reconnect, reach max retries/);
log.end(done);
});
});
});
it('should not try to reconnect multiple times', function (done) {
var log = new Syslog({
connection: {
type: 'tcp',
ip: '127.0.0.1',
port: 64993
}, reconnect: {
enabled: true,
maxTries: 100,
initalDelay: 0,
delayFactor: 0,
maxDelay: 0
}
});
server.once('connection', function (socket) {
socket.destroy();
});
log.connect(function () {
var warnings = 0;
log.on('warn', function () {
warnings++;
});
log.once('error', function (err) {
warnings.should.equal(100);
err.should.match(/Unable to reconnect, reached max retries/);
log.end(done);
});
});
});
it('should buffer messages for delivery when connected', function (done) {
var log = new Syslog({
connection: {
type: 'tcp',
ip: '127.0.0.1',
port: BIND_PORT
}
});
server.once('connection', function (socket) {
socket.once('data', function (chunk) {
log.end(done);
});
});
log.on('warn', function (err) {
console.log(err.stack);
});
log.write({ msg: 'hello' });
log.connect();
});
xit('should not lose messages on write errors', function (done) {
// implement the ring buffer thing and a protection layer rather than a direct pipe
});
});