Skip to content

async-cl/flux

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Flux - A Haxe Stack for Node.js

Formerly cloudshift, name changed due to clash with an existing cloud product.

See documentation here http://flux.async.cl

Flux is written and maintained by Ritchie Turner (ritchie@async.cl) and is currently under heavy development; the apis are subject to change.

Flux hides the Node.js api, and attempts to be a general comprehensive stack for async programming in Haxe, so that as other async libraries appear Node.js could be swapped out. In the short term, Node.js is the first choice platform.

Core Module

Flux provides a consistent set of abstractions on client and server for dealing with common problems:

  • Asynchronous haXe remoting for inter tier and sub-process communication
  • Outcome<A,B> (a Future<Either<A,B>>) as the means for dealing with async callback hell and error handling with helper functions provided as Mixins.
  • Mixins, mostly the Stax prelude extensions.
  • Observables - Typical observer functionality.

Http Module

Simplest example …

Http.server()
.root("/dir/to/serve")
.start({host:"localhost",port:8080});

and/or provide multiple handlers per url, e.g.

Http.server().handler(~/^\/remotes/,rem.httpHandler)   

For haXers a limited Neko api is also supported on handler req/resp objects to get you going.

Channel Module

Publish/subscribe with session management, channel security. Currently a Push implementation.

Http.server().root("www").start({host:"localhost",port:8082})
  .outcome(function(http) {
      Session.manager().start(http)
        .outcome(function(sess:SessionMgr) {
            sess.authorizer(sessAuth);
            Channel.server()
              .authorizer(channelAuth)
              .start(sess).outcome(startRooms);
          });
    });

Once you have your client or server, you may get a channel and pub/sub

function startRooms(channelServer:ChannelServer) {
channelServer.channel("/chat/room").outcome(function(room) {
    room.pub("blah");
    room.sub(function(msg) {
       
    });
});

Data Module

There is a database component with, so far, one driver, Sqlite3. The api is asynchronous and NoSQL where objects are stored in “buckets”. JSON is the default storage format but you may add serializers per bucket if you prefer to store haXe serialized objects or anything else.

Data provides a general indexing facility which utilises the underlying sqlite indexes. Objects are relatable and queryable across buckets.

The Sqlite driver is a popular C++ module for Node.js supported by many of the leading names in the Node.js community. It’s asynchronous and embedded in the node.js instance.

So, each Flux instance has it’s own database, this can be easily augmented so that each instance running talks to a central Flux instance just running data services. Flux provides a remote api compatible driver for this purpose.

Data.store(REMOTESQLITE("http://localhost:8082/data")).outcome(function(store) {
store.bucket("woot").outcome(function(woot) {
   
    woot.where('name="lore"').outcome(function(recs) {
        trace(recs.stringify());
      });
    
    woot.insert({email:"lorena@ritchie.com",name:"lore",passwd:"and why not"})
      .outcome(function(u) {
          trace("lore's id = "+Data.oid(u));
      });
  });

Data also supplies a persistent hash.

The main point here is to think of the Node.js/Sqlite3 combination as a database server in it’s own right

Worker Module

Extend Worker and create seamless sub process workers using the haXe remoting protocol.

Sys Module

File I/O, Process services wrapped in Outcomes as appropriate for this kind of usage:

Sys.writeFile("woot","hi there")
  .oflatMap(function(file) {
        return file.stat();
    })
  .omap(function(stat) {
      return stat.path;
    })
  .oflatMap(function(path) {
      return path.rename("niceone");
    })
  .outcome(function(newFileName) {
      trace("cool "+newFileName);
          
      var p = Sys.events();
    
      p.observe(function(o) {
          switch(o) {
          case ProcessUncaughtException(ex):
            trace("uuncauthg exp:"+ex);
          default:
          }
        });

      trace(Sys.argv());
      trace(Sys.title());
      trace("osuptime:"+Sys.osUptime()+", uptime:"+Sys.uptime());
      });

Installation and Dependencies

install node.js for your platform

  • npm install formidable
  • npm install sqlite3
  • haxelib install nodejs
  • haxelib install flux

Note, the outflux haxelib does not include the nodejs dependency by default, as the outflux lib is used on both client and server having the -D nodejs defined automatically on the client is an unwanted side effect. So be sure to install nodejs bindings manually.

About

a Haxe stack for Node.js

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published