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

leadlight

v0.0.0

Published

Lightweight data/object mapping framework. Wrap any persistence system with domain model functionality.

Downloads

4

Readme

Leadlight - a lightweight data framework for Node.js.

img

Wrap any persistence system with domain model functionality.

This means:

(1) a way of mapping data from the native format (e.g. relational data, json data) to the domain model (application level mapped objects) that can flexibly handle domain model relations (assembly of objects related by domain meaning without hitting the n+1 problem).

(2) a typical model/active record lifecycle that can include validation and spawn events

Rationale

Problem with existing solutions:

  • ORMs have not been very successful in the Node space.
  • ORMs have trouble adjusting to different types of databases (nosql)

Objective

Create a 'light approach' to building abstractions above databases. Work on abstractions that can model data at an application level but push developer work toward the integration with the database.

A developer should be able to meaningfully describe the domain level using familiar ORM like phrases - 'models', 'has many', 'validation', etc. - but the queries themselves will have to be configured or handwritten to suit the environment.

A README to build a description of the DSL and features is below.

Models

//names are passed into the Model definition so these models can be rebuilt wherever
var Person  = new Model('Person', 'db_collection_mapping'); 
//in another file, etc.
var Person = require('LDF').models['Person'];

Fields on a model need to

  • have a name corresponding with a field in the db, to allow value mapping
  • have ordered arrays of lifecycle functions

For example:

Person.fields.push('email'); 

//this means that building the object will rely on correspondence between 'email' on the person 
// instance and 'email' in the data sent from the db.

Person.email.validations.push(
    'Email must be a valid email address!', 
    function(email){ ... //validates format of email }
);

This would play out as:

var person = new Person();
person.email = "nicholasf.gmail.com";
persona.save(function(err, person) {
    console.log(err);
});

> 'Email must be a valid email address!'

person.email = "[email protected]";
person.save(function(err, person) {
    console.log(result);
})

> Person[id: 1, email: '[email protected]']; 

General Behaviours and DB specific Handlers

The model defines a set of standard behaviours - find, create, save, destroy.

Person.find( { id: n })
Person.find( { ids: [n] } ) 
Person.find( { query: "..." } ) 

By themselves these, however, do nothing but call an underlying handler which can be crafted to fit application and database needs.

For example:

Person.behaviours = require('postgres-finders');
Person.behaviours = require('riak-finders');

function findHandler(args) {
    console.log(args);
    //SQL, Riak call, etc., made here
}
> { id: 1, with: [House] }

(I need to list the behaviours above.)

Model Relationships, the n+1 problem

To avoid the n+1 problem, LDF will allow handcrafted queries in the handlers which can be overridden at a fine grained level.

In this example Person and House are models. A Person can have many Houses.

var Person  = new Model('Person', 'db_collection_mapping'); 
var House   = new Model('House', 'db_collection_mapping');

Person.has.push(House); //use arrays so multiple assignments can be made at once
House.belongsTo.push(Person);

Person.find( { id: n, with: ['House'] })

The underlying handler would decide how to return a person with a house. This would involve

  • the query to the db
  • the assembly of the object

The handler would then need to be able to insert data into the Person model and ensure that it's validations, etc. are meant.

TODO:

  • define Model lifecycles and events - validate, save, create, destroy
  • define handlers - map out some basic ones
  • think of a good name for the project, perhaps something to do with 'light'.
  • represent Transactions at a Model level