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

entityjs

v0.3.0

Published

Entity Framework for Node.js

Downloads

14

Readme

EntityJs

A library that provides .net style entity framework for Typescript/Node.js. Currently supports Google Cloud store.

Some of the notable features:

  • Typescript decorator based.
  • Supports Google Cloud store.
  • Provides tracking properties of entities.
  • Supports reference entities.
  • Supports local caching.

Usage

For complete sample app: https://github.com/fieryorc/entityjs-sample

Declaring entity:

// Creates a new entity class for storing it in google cloud store.
class EmployeeEntity extends CloudStoreEntity {

    public static KIND = "employee";

    /**
     * This means the property is a primary key.
     * Every CloudStoreEntity should have one and only primary key.
     */
    @PrimaryKeyProperty()
    public id: string;

    /**
     * This means the property is a value property.
     */
    @ValueProperty()
    public name: string;

    /**
     * Represents reference property.
     * Reference properties are not loaded by default. You need to load explicity using
     * .load() on them.
     */
    @ReferenceProperty(EmployeeEntity)
    public manager: EmployeeEntity;

    public constructor() {
        super(EmployeeEntity.KIND);
    }
}

Creating new context

// Create a new context. Context provides the necessary bindings to the datastore. 
// entityjs comes with two data stores. InMemoryDataStore and CloudDataStore.
// You need to set context for entities to use functions that interact with the store (load, save, etc).

var context = new DataContext(new InMemoryDataStore({}}));

Adding new entity to DB

var employee = new EmployeeEntity();
employee.setContext(context);
employee.id = id;
employee.name = "Prem Ramanathan";
employee.save()
    .then(() => console.log("employee saved to DB"))
    .catch(err => console.log("save() failed: " + err);

Loading entity from DB

var employee = new EmployeeEntity();
employee.setContext(context);
employee.id = id;

// Calling load() loads the entities from data store.
employee.load()
  .then(isLoaded => {
    if (isLoaded) {
      assert(EntityState.LOADED, employee.getState());
      console.log(`Entity loaded. Name = ${employee.name}.`);
    } else {
      console.log(`Entity with id($(employee.id) doesn't exist.`);
    }
  })
  .catch(err => {
    console.log(`Data access failure: ${err}`);
  });

Reference handling

var employee = new EmployeeEntity();
employee.setContext(context);
employee.id = id;
employee.load()
  .then(isLoaded => {
    if (isLoaded) {
      // By default reference entities are created, but not loaded.
      // You need to call load() on them to load it.
      assert(EntityState.NOT_LOADED, employee.manager.getState());
      assert.not.null(employee.manager.id);
      return employee.manager.load();
    }
  })
  .then(isLoaded => {
    if (isLoaded) {
      console.log("reference entity loaded.");
    }
  })

For more examples, look at samples and test directory.

Dev Documentation

# Make sure you have git,vscode and npm installed in your machine.
git clone https://github.com/fieryorc/entityjs
cd entityjs 
npm install -g gulp typings tsc
npm install
typings install

Building from command line

From the src directory, run 'gulp'

Using VS Code (preferred method)

Visual Studio Code provides auto completion which makes it easy to discover and write code.
- Install visual studio code
- Open the root of the repository in VS Code (Not src.. YOU SHOULD ALWAYS OPEN THE ROOT DIRECTORY).
- Edit the code as necessary
- Press 'Ctrl + Shift + B' to build.
  * Once build starts, it will keep running. As soon as the update to a file is made it will rebuild.
  * In other words, as soon as you save a file, it will generate new build. 

To add new typescript definition

# Typescript definition files provide the necessary information for Typescript compiler
# to validate type information. This also is the source of intellisense. All typescript
# definitions are maintained and managed by the command typings.

typings install <name-of-tsd> --save --global

To add new dev dependency (mostly not required)

# Dev dependencies are node modules that are added to help in build tooling.
# When you add them, you need to run the following command so it saves the dependency
# in the package.json.

npm install <module-name> --save-dev