Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
damless
Advanced tools
Readme
DamLess help you to create a NodeJS stream api (with http chunk).
Develop your http server like a gulp script.
const DamLess = require("damless");
const damless = new DamLess();
damless
.config({ http: { port: 3000 }})
.inject("info", "./services/info")
.inject("user", "./services/user")
.get("/helloworld", "info", "helloworld")
.post("/user", "user", "insertOne")
.start();
class Info {
// helloworld is declare as GET:/helloworld
helloworld(context, stream, headers) {
stream.write("Hello");
stream.end("world");
}
}
const { Transform } = require("stream");
class User {
insertOne(context, stream, headers) {
// Read a JSON stream request and write a response as a JSON stream.
stream
.pipe(new Transform({
objectMode: true,
transform(chunk, enc, callback) {
// save the chunk (user) in the database
callback(null, chunk);
}
}))
.pipe(stream);
}
}
npm install damless --save
(context, stream, headers) like http2 interface
class ServiceInfo {
};
text(context, stream, headers) {
stream.write("Hello");
stream.end("world")
};
json(context, stream, headers) {
stream.write({ name: "peter" });
stream.end({ name: "folk" });
};
exports = module.exports = ServiceInfo;
DamLess use givemetheservice to inject all services.
You can override all damless functions or inject your new services.
It's is easier to test your api.
DamLess has been inspired by the http2 syntax. The request and response are wrap by an unique duplex stream. This stream automatically stringify, gzip or deflate your response. It is useless to pipe a compressor.
Use the power of ES6 to easily extends services.
const { Json } = require("damless");
const moment = require("moment");
const { ObjectID } = require("bson");
class CustomJson extends Json {
constructor() {
super();
}
// override the default onValue to deserialize mongo ObjectID
onValue(key, value) {
if (/\d{2}-\d{2}-\d{2}/.test(value)) return moment(value, "YYYY-MM-DD").toDate();
if (ObjectID.isValid(value)) return new ObjectID(value);
return super.onValue(key, value);
}
}
exports = module.exports = CustomJson;
The default json serializer is declared in the DI as "json". Replace it to load your service.
damless
.inject("json", "./custom-json.js")
You can configure damless in javascript or via json file.
damless
.config("./damless.json")
.config({ http: { port: 3000 }})
.config(config => {
config.env = "dev"
})
{
"services": "./services.json",
"http": {
"port": 3000
}
}
You can declare your services in an other json file.
{
"services": [
{
"name": "info",
"location": "./services/info"
}
],
"http-routes": [
{
"get": "/",
"service": "info",
"method": "text"
}
]
}
Retrieve the config object in your service.
class ServiceInfo {
// config will be injected by our DI
constructor(config) {
console.log(config.http.port);
}
};
To run our examples, clone the Damless repo and install the dependencies.
$ git clone https://github.com/BenoitClaveau/damless --depth 1
$ cd damless
$ npm install
$ cd exemples/helloworld
$ node server.js
To run our tests, clone the Damless repo and install the dependencies.
$ git clone https://github.com/BenoitClaveau/damless --depth 1
$ cd damless
$ npm install
$ cd tests
$ node.exe "../node_modules/mocha/bin/mocha" .
FAQs
Streamify your web server
The npm package damless receives a total of 53 weekly downloads. As such, damless popularity was classified as not popular.
We found that damless demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.