Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

k7

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

k7 - npm Package Compare versions

Comparing version 1.0.2 to 1.5.0

API.md

18

lib/index.js

@@ -5,18 +5,22 @@ 'use strict';

const K7 = require('./k7');
const Loader = require('./loader');
exports.register = (server, options, next) => {
const k7 = new K7(server, options);
server.expose('k7', k7);
const loader = new Loader(server, options);
k7.load();
loader.load((err, database) => {
server.decorate('server', 'database', k7.database);
if (err) {
return next(err);
}
return next();
server.decorate('server', 'database', database);
return next();
});
};
exports.register.attributes = {
pkg: require('../package.json')
pkg: require('../package.json')
};
{
"name": "k7",
"version": "1.0.2",
"description": "Connect your database with Hapijs made easy",
"main": "index.js",
"scripts": {
"test": "semistandard && lab",
"test-cov-html": "lab -r html -o coverage.html"
},
"repository": {
"type": "git",
"url": "git+https://github.com/thebergamo/k7.git"
},
"version": "1.5.0",
"repository": "git://github.com/thebergamo/k7",
"main": "lib/index.js",
"keywords": [

@@ -20,11 +13,8 @@ "database",

],
"author": "Marcos Bergamo <marcos@thedon.com.br>",
"license": "ISC",
"bugs": {
"url": "https://github.com/thebergamo/k7/issues"
"engines": {
"node": ">=4.0.0"
},
"homepage": "https://github.com/thebergamo/k7#readme",
"dependencies": {
"glob": "7.0.x",
"hoek": "3.0.x"
"hoek": "4.0.x"
},

@@ -35,7 +25,16 @@ "peerDependencies": {

"devDependencies": {
"code": "2.x.x",
"code": "3.x.x",
"hapi": "10.x.x",
"lab": "10.x.x",
"semistandard": "7.x.x"
}
"lab": "10.x.x"
},
"scripts": {
"test": "lab -m 5000 -t 100 -v -La code",
"test-cov-html": "lab -m 5000 -r html -o coverage.html -La code"
},
"author": "Marcos Bergamo <marcos@thedon.com.br>",
"bugs": {
"url": "https://github.com/thebergamo/k7/issues"
},
"homepage": "https://github.com/thebergamo/k7#readme",
"license": "ISC"
}

@@ -5,8 +5,5 @@ ![k7 Logo](images/k7.png)

[![Build Status](https://travis-ci.org/thebergamo/k7.svg)](https://travis-ci.org/thebergamo/k7)
[![Dependencies Status](https://david-dm.org/thebergamo/k7.svg)](https://david-dm.org/thebergamo/k7)
[![DevDependencies Status](https://david-dm.org/thebergamo/k7/dev-status.svg)](https://david-dm.org/thebergamo/k7#info=devDependencies)
[![Known Vulnerabilities](https://snyk.io/test/npm/k7/badge.svg)](https://snyk.io/test/npm/k7)
[![js-semistandard-style](https://img.shields.io/badge/code%20style-semistandard-brightgreen.svg?style=flat-square)](https://github.com/Flet/semistandard)
[![Build Status](https://secure.travis-ci.org/thebergamo/k7.svg)](http://travis-ci.org/hapijs/good)![Current Version](https://img.shields.io/npm/v/k7.svg)
Lead Maintainer: [Marcos Bérgamo](https://github.com/thebergamo)

@@ -17,4 +14,2 @@ K7 is the simplest way to connect Hapi.js with your favorite Database Mapper, you can use any of ours available connectors for the most populars Databases.

For example:
```javascript

@@ -49,3 +44,3 @@ const Hapi = require('hapi');

This example does:
This example does the following:
1. Setting the k7-mongoose adapter

@@ -55,14 +50,2 @@ 2. Setting the connectionString for mongoose connect

## Options
k7 have minimal options, and the major options are specified in ours Adapters.
* **connectionString**: Is a common option, specified a connectionString to connecto in your database.
* **connectionOptions**: Is a common option, where you will specify the options passed for the connector.
* **models**: Is a common option, where you will specify how we can find your models. **Default**: `models/*.js` In this option you can pass a String or an Array of files or glob patterns like: `**/model.js`
## Where my Models?
Your models will be available in `server.database` all of your databases will be there. In `server.database` have the instance of the Database Mapper used too.
If your model are in a file called `models/user.js`, the model will be avaiblable as `server.database.User`.
## Adapters

@@ -73,8 +56,5 @@ * [k7-bookshelf][k7-bookshelf] (WIP)

## Write your own adapter
The K7 API is very simple, your adapter just need be a Class and export a function `load` and return an Object with all models and the Database Mapper instance for k7 decorate the database in Hapi.js.
For more examples, please see the source code in the [k7-sequelize][k7-sequelize] plugin.
## API
## Testing
For testing you just need clone this repo and run `npm install && npm test` inside root folder of this project.;
See the [API Reference](API.md).

@@ -85,1 +65,2 @@

[k7-bookshelf]: https://github.com/thebergamo/k7-bookshelf

@@ -11,3 +11,3 @@ 'use strict';

const Adapter = require('./adapter');
const Adapter = require('./fixture/adapter');

@@ -21,77 +21,101 @@ // Test shortcuts

describe('K7', () => {
let server;
let options = {
const adapterOptions = {
connectionString: 'mongodb://localhost:27017/k7',
models: 'test/**/model.js',
adapter: Adapter
};
};
it('should register the plugin', (done) => {
server = new Hapi.Server();
const register = {
register: require('../index'),
options
};
describe('k7', () => {
server.register([register], (err) => {
// No errors
let server;
expect(err).to.not.exist;
it('should register the plugin', { plan: 3 }, (done) => {
// Instance of K7 should be registered
server = new Hapi.Server();
const register = {
register: require('../lib/index'),
options: adapterOptions
};
expect(server).to.deep.include('database');
expect(server.database).to.be.an.object();
server.register([register], (err) => {
// No errors
done();
expect(err).to.not.exist();
// Instance of K7 should be registered
expect(server).to.include('database');
expect(server.database).to.be.an.object();
done();
});
});
});
it('should register the plugin with an array of models in options', (done) => {
server = new Hapi.Server();
it('should register the plugin with an array of models in options', { plan: 3 }, (done) => {
options.models = [options.models];
server = new Hapi.Server();
const register = {
register: require('../index'),
options
};
adapterOptions.models = [adapterOptions.models];
server.register([register], (err) => {
// No errors
const register = {
register: require('../lib/index'),
options: adapterOptions
};
expect(err).to.not.exist;
server.register([register], (err) => {
// No errors
// Instance of K7 should be registered
expect(err).to.not.exist();
expect(server).to.deep.include('database');
expect(server.database).to.be.an.object();
// Instance of K7 should be registered
done();
expect(server).to.include('database');
expect(server.database).to.be.an.object();
done();
});
});
});
it('should register the plugin with adapter as string', (done) => {
server = new Hapi.Server();
options.adapter = '../test/adapter';
it('should register the plugin with adapter as string', { plan: 3 }, (done) => {
const register = {
register: require('../index'),
options
};
server = new Hapi.Server();
adapterOptions.adapter = '../test/fixture/adapter';
server.register([register], (err) => {
// No errors
const register = {
register: require('../lib/index'),
options: adapterOptions
};
expect(err).to.not.exist;
server.register([register], (err) => {
// No errors
// Instance of K7 should be registered
expect(err).to.not.exist();
expect(server).to.deep.include('database');
expect(server.database).to.be.an.object();
// Instance of K7 should be registered
done();
expect(server).to.include('database');
expect(server.database).to.be.an.object();
done();
});
});
});
it('should register the plugin with adapter as string', { plan: 1 }, (done) => {
server = new Hapi.Server();
adapterOptions.adapter = '../test/fixture/fake';
const register = {
register: require('../lib/index'),
options: adapterOptions
};
server.register([register], (err) => {
// No errors
expect(err).to.exist();
done();
});
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc