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

daome

v1.0.6

Published

Direct Access Object for Mongoose with Express.js

Downloads

11

Readme

Direct Access Object for Mongoose with Express.js

NPM

  • Easy dataTable
  • Auto API
  • Autonomous & standalone system
  • Auto modal (but require jquery)
  • Server and client
  • Fine permission control possibility
    • By API type (create, update...)
    • By Fields
  • Templates are based on EJS

Install

From server side

npm install daome

From client side

<script src="/yourPath/dao/assets/app.js"></script>

Introduction

Mongoose provides the method to manage the model. DAOME does not include this feature.

That why you have to define your own model using Mongoose before anything.

As DAOME provides the controller and views is it important to point that input validation is made by the model (Mongoose Model). But DAOME accepts access and priviledges control.

Server API is separed in 3 features:

  • The controller which will manage requests with express.js
  • The view manager (server and client side)
  • The express.js initializer

Real life example

### Server side

Initialise the DAOME module:

var daome = require("daome");

/* create a specific context where app is the express.js app handler. */
var daomeCtx = new daome(app, "/admin/dao");

/* All Web services (for the current context) are accessible from /admin/dao */

Define your Mongoose model as following (like we create a user backend management) :

this.userSchema = new Schema({
	name: {type: String, required: [true, "Please fill a valid name"] },
	mail: {
		type: String, 
		lowercase: true, 
		required: [true, "Please fill a valid mail address"],
		unique: [true, "Can not create account"],
		match: [/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/, 'Please fill a valid email address'] 
	},
	password: {
		type: String, 
		set: passwordSetter, // can be a HMAC conversion
		required: [true, "Please fill a valid password"] 
	},
	session: {type: String, unique: true, default: function() {
		return(jen.password(25, 60))
	} },
	admin: {type: Boolean, default: false },
	verified: {type: Boolean, default: false },
	createDate: { type: Date, default: Date.now }
});
this.userModel = mongoose.model('user', this.userSchema);

/* create a daome controller */
this.userController = daomeCtx.controller("user", this.userModel);

Once the model is create we define the server side DAOME up layer controller :

/* create a daome controller */
this.userController = daomeCtx.controller("user", this.userModel);

/* permission controller important to define */
this.userController.permission = function(req, sw, field) {
	if(isAdmin != true)
		return(false);
	return(true);
}

this.userController.views({
		name: {
			title: "User name",
			help: "Enter the account owner first and last name",
			editable: true,
			search: true,
			table: true,
			type: "text",
			/* do not set name */
			attr: {
				placeholder: "Give a name"
			},
		},
		mail: {
			title: "Login mail",
			help: "The mail address is used as user login",
			editable: true,
			search: true,
			table: true,
			type: "text",
			/* do not set name */
			attr: {
				placeholder: "Give a login address"
			},
		},
		password: {
			title: "Password",
			help: "Login password (make sure the password is safe)",
			editable: true,
			get: function(text) {
				return('');
			},
			type: "password",
		},
		
		verified: {
			title: "User verification",
			help: "Is the user confirms its subscribtion",
			editable: true,
			type: "checkbox",
			attr: {},
		},
		
		admin: {
			title: "Administration level",
			help: "Is the user can administrate the platform ?",
			editable: true,
			type: "checkbox",
			attr: {},
		},
		
		createDate: {
			attr: {}
		},
});

/* by doing this you expose the database to the Web */
daomeCtx.publish(this.userController);

Well done for the server side

### Client side

DAOME can be used of 2 ways. The first is a easy way where the dataset, modals and everything are generated by DAOME, but it requires you install bootstrap framework on your website. The other way calls as standalone way does not required any additionnal framework, it works alone.

In our example we use modals then we need Bootstrap.

<!DOCTYPE html>
<!--[if IE 9 ]><html class="no-js ie9"><![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--><html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
<script src="/admin/dao/assets/app.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
</head>
<body>
<div class="site-wrapper">
<div id="userModal"></div>

<div class="container">
	<header class="page-header">
		<h1>Users settings </h1>
	</header>
	
	<div class="container">

				<button id="userAdd" type="button" class="btn btn-primary">
				 Add user
				</button>

						
				<div id="userSearch">
				</div>
				<div id="userContent">
				</div>
				<div id="userPages">
				</div>
		</div>
	</div>
</div>



<script>
(function() {
	var userDao = new daome("user", "/admin/dao");
	var userDaoModalId = null;
	userDao.connect(function() {

		var addViews = {
			adminLabel: {
				title: "Is admin",
				table: true,
				get: function(id, doc, th) {
					var label = document.createElement("label");
					
					if(doc.admin == true) {
						label.setAttribute("class", "label label-danger");
						label.innerHTML = "YES";
					}
					else {
						label.setAttribute("class", "label label-success");
						label.innerHTML = "NO";
					}
	
					return(label);
				},
				attr: {},
			},
			activateLabel: {
				title: "Verified",
				table: true,
				get: function(id, doc, th) {
					var label = document.createElement("label");
					
					if(doc.verified == true) {
						label.setAttribute("class", "label label-success");
						label.innerHTML = "YES";
					}
					else {
						label.setAttribute("class", "label label-warning");
						label.innerHTML = "NO";
					}
	
					return(label);
				},
				attr: {},
			},
			
			buttonsDelete: {
				table: true,

				get: function(id, doc, th) {
					/* Edit button */
					var button = document.createElement("button");
					button.setAttribute("class", "btn btn-xs btn-secondary");
					button.setAttribute("data-mid", doc._id);
					button.innerHTML = "Delete";
					
					button.onclick = function() {
						var id = button.getAttribute("data-mid");
						userDao.modalRemove("Are you sure to want remove server ?", id);
					};
	
					return(button);
				},
				attr: {},
			},
			
			buttonsEdit: {
				table: true,

				get: function(id, doc, th) {
					/* Edit button */
					var button = document.createElement("button");
					button.setAttribute("class", "btn btn-xs btn-secondary");
					button.setAttribute("data-id", id);
					button.setAttribute("data-mid", doc._id);
					button.innerHTML = "Edit";
					
					button.onclick = function() {
						var id = button.getAttribute("data-mid");
						userDao.modalUpdate("Update satellite server informations", id);
					};
	
					return(button);
				},
				attr: {},
			},
			buttonsView: {
				table: true,

				get: function(id, doc, th) {
					/* View button */
					var button = document.createElement("button");
					button.setAttribute("class", "btn btn-xs btn-primary");
					button.setAttribute("data-id", id);
					button.setAttribute("data-mid", doc._id);
					button.innerHTML = "Detail";
					
					button.onclick = function() {
						var id = button.getAttribute("data-mid");
						userDao.modalView("Futher about sattelite server", id);
					};
					
					return(button);
				},
				attr: {},
			},
		}	
		

		userDao.views(addViews);
		
		userDaoModal = userDao.generateModal("userModal");
		userDaoSearch = userDao.generateSearch("userSearch");
		userDaoTable = userDao.generateTable("userContent");
		userDaoTable = userDao.generatePagination("userPages");

		$('#userAdd').click(function() {
			userDao.modalCreate("Create new server entry");
		});
    
	});
})();
</script>

</div>

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>

</body>
</html>