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

neogen

v1.0.26

Published

Code generation tool for `neogma`

Downloads

45

Readme

neogen

GitHub Workflow Status (with event) NPM

What is neogen?

neogen is a code generation tool for neogma, focused on automating and streamlining the development of Neo4j object-graph mappings (OGMs). It facilitates efficient model generation, relationship setup, and method creation, while ensuring type safety in Neo4j-based projects.

What problems does it solve ?

  • Relations validation:
  • Efficiency - neogma introduces great type safety, hints but with it requires more editing: if one property changes - you would need to edit two declaration, neogen tries to solve this issue
  • Structure

Motivation

Developed with inspiration from Ruby on Rails' rails g, neogen eliminates the repetitive and error-prone aspects of manual Neo4j OGM setup in neogma. Its primary goal is to enhance development efficiency and accuracy in managing Neo4j database schemas and relationships.

How to use

Installing

yarn add neogen

Create config file

touch neogen.config.ts

Update your connection

At this point assuming your project' structure to be like this

├── neogen.config.ts
├── package.json
└── src
    ├── index.ts
    ├── neo4j.ts
    └── models

Where neo4j.ts contains instance of Neogma connection:

It's required to add this lines so that neogen could find connection, since models depend on it's value

import { neogen } from "neogen";
// ...
const neogma = new Neogma(...
// ...
neogen.setInstance(neogma)

Write desired schema:

Update neogen.config.ts file:

import { neogen } from "neogen";

neogen.generateAll({ // settings
    generateBase: true,
    outputFolder: './src/models'
}, [{ // models
    label: 'Post',
    schema: {
        uuid: 'string',
        text: 'string'
    },
    primaryKeyField: 'uuid'
}, {
    label: 'User',
    schema: {
        name: 'string',
        uuid: 'string',
        online: 'boolean'
    },
    primaryKeyField: 'uuid'
}], { // relations
    POST_POSTED_BY: {
        User: 'posted',
        Post: 'of_user',
    },
    POST_LIKED_BY: {
        User: 'likes',
        Post: 'liked_by'
    },
})

Adjust your package.json

"scripts": {
    "neogen": "ts-node neogen.config.ts",

And finally run

yarn run neogen

Result

With this configuration it'll generate 6 files

├── neogen.config.ts
├── package.json
└── src
    └── models
        ├── __base.ts
        ├── __relations.ts
        ├── post.ts
        ├── post_.ts
        ├── user.ts
        └── user_.ts
  • post, user - the ones containing all type and meta information
  • post_ and user_ - contains static and instance methods of the models
  • __relations - contains all relations defenitions, it's important to import it in main file
  • __base - contains base of instance and statics methods if generateBase option is enabled

Update your main file

It's important to import it in this order in your main/index file before using any models:

import './neo4j' // or whatever your file with neo4j connection is named
import './models/__relations'

relations DSL explanation

Give this relationship declrartion:

const rel = {
  POST_POSTED_BY: {
        User: 'posted',
        Post: 'of_user',
    }
}

It would translate to

(:User)-[:POST_POSTED_BY]->(:Post)

Or if you want node relation to itself you can make

const rel = {
  POST_POSTED_BY: {
    Comment: ['replied_to', 'replies']
  }
}

Which would result to

(:Comment)-[:POST_POSTED_BY]->(:Comment)

Or you can use raw relation notation:


neogen.generateAll({
    rawRelation: [
        {
            from: 'Session',
            to: 'Channel',
            direction: 'in',
            label: 'TEST',
            alias: 'test'
        }
        ...

TODO

  • Core
    • [ ] Validate relations
    • [x] Auto instance import
    • [ ] Relation getters
  • Organizational
    • [ ] Eslint
    • [x] Use Github workflow for publishing npm
    • [x] Add tests