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

rilatigi

v0.0.3

Published

A promise-based relationship CRUD library for Node.js

Downloads

2

Readme

Rilatigi

NPM Version David David Build Status codecov Twitter Follow

Rilatigi means to relate in esperanto.

Rilatigi is a promise-based relationship CRUD library for Node.js. It aims to streamline relationship CRUD operations when you have to keep multiple data sources synced (i.e. caching layer and persistence layer).

Rilatigi is data source agnostic and delegates resolution of CRUD operations to resolvers.

CRUD operations are start, end, get and sync. Those operations can be performed on mutual and unmutual relationships.

Installation

npm install rilatigi --save

Usage

Plug in your favourite promise library

Set rilatigi.Promise to your favourite ES6-style promise constructor and rilatigi will use it.

npm install bluebird --save
import Promise from 'bluebird'
import rilatigi from 'rilatigi'

rilatigi.Promise = Promise

Define resolvers

Rilatigi doesn't make any assumption about your resolvers but having start, end, get and sync methods.

Signatures for these methods differ depending on the type of relationship (mutual, unmutual) a resolver manages.

Mutual resolvers

class MutualResolver {
  start (subjects) {

  }
  end (subjects) {

  }
  get (subject) {

  }
  sync (subject, result) {

  }
}

Unmutual resolvers

class UnmutualResolver {
  start (subject, objects) {

  }
  end (subject, objects) {

  }
  get (subject) {

  }
  sync (subject, result) {

  }
}

Define and use relationships

You can define mutual and unmutual relationships.

The Following examples show you both mutual and unmutual relationship definition and usage in the context of multiple data sources (Redis and Mongo).

Definition of resolvers is omitted but you can take a look at the examples

Mutual relationships

import { mutual } from 'rilatigi'
import { redisFriendshipResolver, mongoFriendshipResolver } from './resolvers'

const friendship = mutual([redisFriendshipResolver, mongoFriendshipResolver])

friendship
  .start(['Tom', 'Jerry'])
  .then(() => friendship.get('Tom'))
  .then(result => console.log(result)) // ['Jerry']

Unmutual relationships

import { unmutual } from 'rilatigi'
import { redisSpeakToResolver, mongoSpeakToResolver} from './resolvers'

const speakTo = unmutual([redisSpeakToResolver, mongoSpeakToResolver])

speakTo
  .start('teacher', ['a student', 'another student'])
  .then(() => speakTo.get('teacher'))
  .then(result => console.log(result)) // ['a student', 'another student']

Operations lifecycle

start

When you invoke start on a relationship, rilatigi will sequentially invoke start on its resolvers, starting from the last resolver.

end

When you invoke end on a relationship, rilatigi will sequentially invoke end on its resolvers, starting from the last resolver.

get

When you invoke get on a relationship, rilatigi will sequentially invoke get on its resolvers, starting from the first resolver, until a valid result is returned or all resolvers' get got invoked. Non-valid results are null, undefined, empty strings, empty arrays.

Rilatigi will also invoke sync on all resolvers that returned a non-valid value in order to keep data sources synced.

sync

You shouldn't invoke sync on a relationship. It's for internal use.

License

The project is licensed under the MIT license.