A library for managing data in Node.js and web browsers.
Fortune.js is a library for managing data in Node.js and web browsers. It consists of a data abstraction layer and networking functions.
View the website for documentation. Get it from
$ npm install fortune --save
Fortune.js facilitates sharing data between client and server by sharing most of the same code. The core is a data abstraction layer, which provides querying, persistence, type validation, relationships, and business logic isolation.
The included networking functions provide a basis for implementing application-level protocols, including media types such as Micro API and JSON API, standard input formats such as URL encoded and form data, and also includes its own wire protocol based on Websocket and MessagePack.
The only necessary input is record type definitions. Here's a model of a basic micro-blogging service:
const fortune = require'fortune'const store = fortuneuser:name: type: String// Following and followers are inversely related (many-to-many).following: link: 'user' inverse: 'followers' isArray: truefollowers: link: 'user' inverse: 'following' isArray: true// Many-to-one relationship of user posts to post author.posts: link: 'post' inverse: 'author' isArray: truepost:message: type: String// One-to-many relationship of post author to user posts.author: link: 'user' inverse: 'posts'
storerequesttype: 'user'method: 'create'payload: name: 'John Doe' name: 'Jane Doe'
The first call to
request will trigger a connection to the data store, and it returns the result as a Promise.
Then let's add a HTTP server:
const http = require'http'// The `fortune.net.http` helper function returns a listener function which// does content negotiation, and maps the internal response to a HTTP response.const server = httpcreateServerfortunenethttpstorestoreconnectthen => serverlisten1337
This yields an ad hoc JSON over HTTP API. There are serializers for Micro API (JSON-LD) and JSON API, which also accept HTTP parameters. In addition, Fortune.js implements a wire protocol based on WebSocket and MessagePack.
See the plugins page for more details.
Fortune.js is written in ECMAScript 5.1 syntax, with some ECMAScript 6 additions.
This software is licensed under the MIT license.