![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Warning: This library is under active development, and should not be considered production ready
The Graft project explores what the web could become, if we extended microservice architectures into the client.
Interested in Graft and jsChan? Watch @mcollina presentation at NodeConf.eu 2014, "Full Stack Through Microservices"
When you graft something, it involves joining together parts to create a new whole. One that is hopefully more adaptable, resilient and ultimately interesting.
"Instead of pretending everything is a local function even over the network ..., what if we did it the other way around? Pretend your components are communicating over a network even when they aren't?" -- Docker's Solomon Hykes on LibChan - [link]
graft()
graft.ReadChannel()
graft.WriteChanel()
graft.branch()
graft.where()
spdy.client()
spdy.server()
ws.client()
ws.server()
The main object of this library. A Graft
instance is a
Transform
stream with objectMode: true
.
The objects on the output of a Graft
instance are
Requests. On the input side, you can write just normal JS
objects, and everything else you can write to a jsChan
channel.
These objects will be automatically wrapped up in a Request.
Internally, each Graft
instance is backed by
jschan.memorySession()`.
In order to process the requests, you can just:
var graft = require('graft')();
var through = require('through2');
graft.pipe(through.obj(function(msg, enc, cb) {
console.log(msg); // prints { hello: 'world' }
// process your request
cb();
}));
graft.write({ hello: 'world' });
Returns a nested read channel, this channel will wait for data from the other party.
Returns a nested write channel, this channel will buffer data up until is received by the other party.
Passes the request to the first argument, and if that returns a truthy
value, it calls write(req)
on the associated stream.
It respect backpressure.
Shortcut for the most common usage of graft.branch()
, it allows to
rewrite:
graft.branch(function(msg) {
return msg.hello === 'world'
}, stream)
into:
graft.where({ hello: 'world' }, stream)
Each Graft request is the first message sent on a top-level channel, and it is composed of:
_channel
, the associated channel_session
, the associated sessionEach request will have its own channel, but the session is generic for every client.
The _channel
and _session
properties will not be enumerable.
Creates a new spdy client to pipe to:
var graft = require('graft')();
var spdy = require('graft/spdy');
graft.pipe(spdy.client({ port: 12345 }));
graft.write({ hello: 'world' });
Creates a new spdy server that you can pipe to a graft instance:
var graft = require('graft')();
var spdy = require('graft/spdy');
var through = require('through2');
spdy
.server({ port: 12345 })
.pipe(graft)
.pipe(through.obj(function(msg, enc, cb) {
console.log(msg); // prints { hello: 'world' }
// process your request
cb();
}));
Creates a new ws client to pipe to:
var graft = require('graft')();
var ws = require('graft/ws');
graft.pipe(ws.client({ port: 12345 }));
graft.write({ hello: 'world' });
It works even from a Browser, using WebPack or Browserify.
Creates a new ws server that you can pipe to a graft instance:
var graft = require('graft')();
var ws = require('graft/ws');
var through = require('through2');
ws
.server({ port: 12345 })
.pipe(graft)
.pipe(through.obj(function(msg, enc, cb) {
console.log(msg); // prints { hello: 'world' }
// process your request
cb();
}));
You can even pass an existing http server that will be hooked up, like so:
var graft = require('graft');
var ws = require('graft/ws');
var http = require('http');
var server = http.createServer();
ws
.server({ server: server })
.pipe(graft())
Libchan is the connective tissue to all our endeavours. It is a microservices library announced by the Docker project, and it is going to form the basis of all of the tools they build in the future.
It's most unique characteristic is that it replicates the semantics of go channels across network connections, while allowing for nested channels to be transferred in messages. This would let you to do things like attach a reference to a remote file on an HTTP response, that could be opened on the remote end for reading or writing.
The protocol uses SPDY as it's default transport with MSGPACK as it's default serialization format. Both are able to be switched out, with http1+websockets and protobuf fallbacks planned.
While the RequestResponse pattern is the primary focus, Asynchronous Message Passing is still possible, due to the low level nature of the protocol.
MIT
FAQs
Full-Stack JavaScript Through Microservices
The npm package graft receives a total of 2 weekly downloads. As such, graft popularity was classified as not popular.
We found that graft demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers 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
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.