npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jigsaw.ts

v0.0.1-dev13

Published

jigsaw.ts is a RPC framework under Node.js

Downloads

7

Readme

Jigsaw.ts

npm version

Jigsaw.ts is an RPC framework written in TypeScript, it implements RPC used completely Node.js Socket API to ensure the performance of calling a remote method.

The API of Jigsaw.ts is designed to easy to use.

And the project is Expandable and Maintainable, so your contribution is welcome.

Install

in a npm project folder, run:

npm install jigsaw.ts --save

Easy-to-start Sample

serv.js

const RPC = require("jigsaw.ts");
new RPC.domain.Server();

let jg = RPC.GetJigsaw({ name :"calculator" });

jg.port("add",({a,b})=>{
    return {
        msg:"Hello, World!",
        result:a + b,
        date:new Date().toString()
    }
});

app.js

const RPC = require("jigsaw.ts");

jg.send("calculator:add",{ a:3, b:7 }).then((res)=>{
    console.log(res);
})

then run this two scripts:

You will get this output

{
    msg: "Hello World!",
    result: 10,
    date:'--Now Date String--'
}

High Performance

Jigsaw implemented through Node.js Socket API completely.

A single Jigsaw instance can almost transfer 1000 requests/sec, 20MB/s data with low latency in LAN on a x86, Intel i5-8250, GBE Network Card computer.

Simple API Document

1. GetJigsaw({ name :string, entry :string, registry :string }) : Jigsaw

jigsaw name is a path about how to access this jigsaw, network address and jigsaw name will both sync to registry.

the name is the jigsaw name which is a property of the return instance.

entry is a network address string like "8.8.8.8:1234", this address described how to access this jigsaw from remote. so if this jigsaw work on Internet, this address must be a Internet Address.

jigsaw will listen on the port number like '1234' you provided, if you don't want to specified a exact number, just set entry like "127.0.0.1" without port string.

registry is a URL of the Network Address of the Jigsaw Domain Registry. The format is like "jigsaw://127.0.0.1:3793/"

You can create a registry like this:

new RPC.domain.Server(3793)

So GetJigsaw() 's calling format is like:

let jg = RPC.GetJigsaw("iamjigsaw","127.0.0.1","jigsaw://127.0.0.1:3793/")

All the params has default value, if you just want this jigsaw work on Local Network:

let jg = RPC.GetJigsaw()

2. Jigsaw

2.1 Jigsaw.prototype.constructor( name :string , entry_address :string , entry_port :number , registry_path : URL) : Jigsaw

This is the original Jigsaw constructor, build an instance without the factory method 'GetJigsaw()'.

Notice that registry_path must use require("url").parse() to get the url object

2.2 Jigsaw.prototype.send( path :string , data :object) : Promise(object)

call this method to invoke a remote jigsaw's method.

the path must be a correct Jigsaw Path format:

JigsawName:port_name

the data must be a JSON-Serializable JavaScript Object which doesn't contain any 'undefined' of a 'Function' and some other properties.

2.3 Jigsaw.prototype.port( port_name :string , handler:(data:object)=>Promise(object)) : void

register a Jigsaw Port that will handle all invoking requests to this Port.

Actually, port_name is the method name, and the handler is the function you will receive the invoke object and returning the object you want to reply.

handler can be a Async Function if you want to.

...

const wait = require("util").promisify(setTimeout);

let jgA = RPC.GetJigsaw({name : "A"});
let jgB = RPC.GetJigsaw({name : "B"});

jgA.port("call",async ()=>{

    console.log("recv an invoke,start to wait...");
    await wait(3000);
    console.log("done!");

    return {hello:"world"};
})

jgB.send("A:call",{}).then(console.log);

this data object can be 1MB or even bigger.

2.4 Jigsaw.prototype.handle(handler : (port_name:string,data:object)=>Promise(object))

if a invoke request doesn't match any Jigsaw Port, it can be caught through this method.

...

jg.port("call_1",()=>{});

jg.handle((port_name,data)=>{
    console.log(port_name,data);
    //output: call_2 {abc:123}
});

jg.send("call_2",{abc:123});

handler can be a Async Function if you want to.

LICENSE

This project is open-source under GPL-2.0 license.

Contribution💗

Your contribution is welcome, follow this steps

1. Fork this repository
2. Modify the codes, or write a mocha test case
3. Commit using 'cz-convention-changelog'
4. Start a Pull Request