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

wirentity

v1.2.5

Published

Wirentity

Downloads

245

Readme

##Wirentity

###How the Entity client works ...


import { Entity, EntityTransport } from 'wirentity';

let httpClientTransport = new EntityTransport(EntityTransport.HTTP);

await httpClientTransport.connect({ host: 'http://localhost', port: 3001 });

        // ** create entity with this transport
let UserEntity = Entity.generateClass(httpClientTransport, 'users', '_id');

// ** All actions are returning a promise

// ** INSTANCE METHODS

// ** imagine we created a user object
// ** let user = await UserEntity.create({age: 18, name: "Trump"});

// ** set the key, val pair or an object {}
user.set("age", 20);
user.set({firstName: "Jhon", lastName: "Snow"});

user.get(key);

// ** reset the key value to the last saved snapshot's value
user.reset(key);

// ** check if there are any changes not saved
user.isDirty();

await user.save();

// ** gets the object of user
user.value();

// ** returns user id
user.getId();

// ** removes the user
await user.remove();

await user.runCommand(command, data);

// ** STATIC METHODS

// ** entityAction = { action: 'create', payload }
let user = await UserEntity.create({age: 18, name: "Trump"});

// ** entityAction = { action : 'loadById',  payload: { query: { id }, select } } 
let user = await UserEntity.loadById(id);

// ** entityAction = { action: 'loadAll', payload : { select } }
let allUsers = await UserEntity.loadAll({select});

// ** entityAction = { action: 'loadByQuery', payload : { query, select, limit, skip } }
let users = await UserEntity.loadByQuery({ query, select, limit, skip });

// ** entityAction = { action : 'updateById', payload: { query: { id }, update } }
await UserEntity.updateById(id, update);

// ** entityAction ={ action: 'update', payload : { query, update } } 
await UserEntity.update(query, update);

// ** entityAction = { action : 'removeById',  payload: { query: { id } } }
await UserEntity.removeById(id);

// ** entityAction = { action : 'removeByQuery',  payload: { query } }
await UserEntity.removeByQuery(id) 

// ** entityAction =  { action: 'runCommand',  payload: { command, data } }
UserEntity.runCommand() 

// ** entityAction = { action: 'incrementById', payload: { query: { id }, bins } }
UserEntity.incrementById(id, bins) 

###How the Entity backend works ...


import { Entity, EntityTransport } from 'wirentity';

let httpBackendTransport = new EntityTransport(EntityTransport.HTTP);
let mongoTransport = new EntityTransport(EntityTransport.MONGO);

// ** Mongo transport
const schemas = [{
    pk: '_id',
    name: 'users', 
    schema:  new Schema({
        name: String,
        age: String
    })
}];

await mongoTransport.bind({ schemas, url: 'mongodb://localhost/wire_entity', options: { debug: false } });
let mongoClient = await mongoTransport.connect();

let httpBackend = await httpBackendTransport.bind();
httpBackend.proxy(mongoClient);


// ** how to add middlewares

httpBackend.use((req, res, next) => {
    // ** something goes here
    // ** you can get the actual entity action with httpBackend.parseRequest(req)
    let { action, collection, payload } = httpBackend.parseRequest(req);
});

// ** adds general middleware for every action for every collection
httpBackend.use(midllewareHandler);

// ** adds middleware for every action for specific collection
httpBackend.use(collection, midllewareHandler);

// ** adds middleware on specific action for all collections
httpBackend.addMiddleware("create", midllewareHandler);

// ** adds middleware on specific action on specific collection
httpBackend.addMiddleware("user.create", midllewareHandler);

###kitoo-core example ... ##client side code

import {Entity, EntityTransport} from 'wirentity';

let kitooClientTransport = new EntityTransport(EntityTransport.KITOO);
async function client() {
	try {
		const client = await kitooClientTransport.connect({host: '127.0.0.1', port: 7896})
		let UserEntity = client.getEntity('users', '_id');
		let user = await UserEntity.create({age: 20, name: "Shelby"});
	} catch (e) {
		console.error(e)
	}
}
client()

##backend side code

import { Entity, EntityTransport } from 'wirentity';
import mongoose from 'mongoose';

const Schema = mongoose.Schema;
let kitooBackendTransport = new EntityTransport(EntityTransport.KITOO);
let mongoTransport = new EntityTransport(EntityTransport.MONGO);

const schemas = [{
	pk: '_id',
	name: 'users',
	schema:  new Schema({
		name: String,
		age: String
	})
}];
async function backend() {
	await mongoTransport.bind({ schemas, url: 'mongodb://localhost/wire_entity', options: { debug: false } });
	let mongoClient = await mongoTransport.connect();

	let kitooBackend = await kitooBackendTransport.bind({router: 'tcp://127.0.0.1:7896'});
	//add middleware to check if user exists
	kitooBackend.addMiddleware("users.create", async (req, res, next) => {
		 if (user.value()) {
		 	return res.json({ error: true });
		 }

		next();
	})

	kitooBackend.proxy(mongoClient);
}
backend();

you must run router aside

import {Router} from 'kitoo-core'

(async function () {
	try {
		let router = new Router({ bind: 'tcp://127.0.0.1:7896' });
		await router.start();
		console.log('router started')
	} catch (err) {
		console.error(err)
	}
}());